gpt4 book ai didi

html - 如何从 HTML 中删除多个空白字符?

转载 作者:行者123 更新时间:2023-11-28 02:04:59 25 4
gpt4 key购买 nike

我想删除来自用户端的额外空白,但我无法预测 HTML 的格式。

例如:

<p> It's interesting that you would try cfsetting, since nothing in it's
documentation would indicate that it would do what you are asking.
Unless of course you were mis-reading what "enableCFoutputOnly" is
supposed to do.


</p>



<p>



It's interesting that you would try cfsetting, since nothing in it's
documentation would indicate that it would do what you are asking.
Unless of course you were mis-reading what "enableCFoutputOnly" is
supposed to do.</p>

请指导我如何从 HTML 中删除多个空白字符。

最佳答案

您可以使用正则表达式将任何多个空白字符的情况替换为一个空格,方法是遍历结果直到不再出现多个空白:

lastTry = "<p>   lots of space    </p>";
nextTry = rereplace(lastTry,"\s\s", " ", "all");
while(nextTry != lastTry) {
lastTry = nextTry;
nextTry = REReplace(lastTry,"\s\s", " ", "all");
}

在 CF10 中测试工作。

关于html - 如何从 HTML 中删除多个空白字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12016282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com