本文介绍了如何从HTML中删除多个空格字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除来自用户端的多余空格,但我无法预测HTML的格式。
I want to remove extra whitespace which is coming from the user end, but I can't predict the format of the 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中删除多个空白字符。
Please guide me on how to remove more than one whitespace character from HTML.
推荐答案
您可以使用regex通过循环遍历结果来替换多个空格字符的所有情况,使用单个空格,直到不再有多个空格出现为止: p>
You could use regex to replace any cases of multiple whitespace characters with a single space by looping over the result until no more multiple whitespace occurances exist:
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中删除多个空格字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!