2

ユーザー側から来る余分な空白を削除したいのですが、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から複数の空白文字を削除する方法を教えてください。

4

3 に答える 3

1

正規表現を使用して、複数の空白文字が存在しなくなるまで結果をループすることにより、複数の空白文字のすべてのケースを単一のスペースに置き換えることができます。

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

CF10で動作確認済み。

于 2012-08-18T06:37:03.543 に答える
0

あなたが完全な怠惰からコードを通してそれをしたくないなら

=> http://jsbeautifier.org/

コードでそれを行いたい場合は、正規表現が別のオプションになります

于 2012-08-18T06:06:42.543 に答える
0

これはそれを行う必要があります:

<cfscript>
  string function stripCRLFAndMultipleSpaces(required string theString) {
    local.result = trim(rereplace(trim(arguments.theString), "([#Chr(09)#-#Chr(30)#])", " ", "all"));
    local.result = trim(rereplace(local.result, "\s{2,}", " ", "all"));
    return local.result;
  }
</cfscript>
于 2014-02-04T10:28:44.960 に答える