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

标签 html coldfusion whitespace coldfusion-8

我想删除来自用户端的额外空格,但我无法预测 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/

相关文章:

html - 如何让一个div包罗万象

html - 如何使用 Watir 访问具有自定义属性的元素?

Coldfusion:api 调用数组和结构上的嵌套循环

serialization - Coldfusion:通过 url 将结构作为字符串传递

coldfusion - 如何在 ColdFusion 9 EXTJS 网格列上设置 typeAhead=true?

Bash 脚本将目录中的所有 flv 文件转换为 mp3

html - 如何使用 CSS 和 Bootstrap 在面板 div 顶部添加图像图标?

php - 使用 PHP 生成 HTML 时处理撇号

c - 空白打印不正确

html - 我找不到在网站底部创建空间的内容