$txt_unclean = trim(nl2br($_POST['txt_content']));
$txt_content = strip_tags($txt_unclean, '<b><i><u><br>');
$txt_br_replace = preg_replace("/[^a-zA-Z0-9 \!\,\?\.\n s]/", '', preg_replace("!(<br(?:\s?/)?>\s*){2,}!s", "<br />\n<br />\n", $txt_content));
好。所以我只允許每行換行2個換行符。例如,如果有9個換行符,則會用兩個換行符替換它。這樣做,我會取得成功的結果。但是,問題是當我想清理使用這個正則表達式的話:/[^a-zA-Z0-9 \!\,\?\.\n s]/
的preg_replace - 保留換行符和消毒一些文字
它基本上刪除所有換行符,但清理單詞。那麼我如何保留換行符?
例如: 我想這一點:
StackOverflow is [email protected]$#@#$#@#@#@!#@@!
I [email protected]$!##$$#!!#[email protected](*[email protected]*
根據正則表達式我寫的,這應該是輸出:
StackOverflow is amazing!!
I KNOW!!!!09
可以顯示原始字符串的例子,你想怎麼它看起來像 – razzak 2013-04-22 18:38:13
我已經更新了。請檢查。 – Cole 2013-04-22 18:42:36