Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您将如何删除额外的换行符,例如:
text text text text text
我希望它是这样的
text text text
我已经在使用 nl2br($desc) 为了让换行符出现在所有现在我如何将它们限制为 1
在使用nl2br()单个换行符替换所有回车符或换行符序列之前:
nl2br()
$result = preg_replace('/[\r\n]+/', "\n", $desc);
在线查看它:ideone
之后nl2br():
$desc = preg_replace('#(<br[ ]?[\/]?>[\r\n]*)+#','<br/>',$desc);