PHP 在使用 nl2br 时忽略空白字符的新行


PHP ignore new lines that are blank characters when using nl2br

如果新行只包含空白字符或为空字符串,在使用 nl2br 时如何忽略它?

替换 2 个或更多个 continue' 和空行,仅替换一个 '

<?php
$text = "Hello
[tab]
[spaces]
      world
";
echo nl2br(preg_replace("/'W+'n+/", "'n", $text));

返回

Hello<br />
world<br />