PHP 从字符串中删除新行
要从字符串中删除换行符,代码如下-
示例
<?php $str = "Demo text for reference"; echo nl2br($str); $str = preg_replace('~[\r\n]+~','', $str); echo "\n".nl2br($str); ?>
输出结果
Demo<br /> <br /> text for <br /> <br /> reference Demo text for reference
示例
现在让我们来看另一个示例-
<?php $str = "Demo text"; echo nl2br($str); $str = str_replace(array("\n", "\r"), '', $str); echo "\n".nl2br($str); ?>
输出结果
Demo<br /> <br /> text Demo text