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.
如果新行只包含空白字符或者是空字符串,使用nl2br时如何忽略?
替换 2 个或更多继续 \n 和空行只为一个 \n
<?php $text = "Hello [tab] [spaces] world "; echo nl2br(preg_replace("/\W+\n+/", "\n", $text));
返回
Hello<br /> world<br />