【发布时间】:2013-05-04 20:00:08
【问题描述】:
如何去掉字符串中的“\n”?
我使用了下面的 3 种方法,只有 "\s+" 有效的接缝,但我只想删除 \n,而不是所有空间,如何完成这项工作?
需要帮助,这个问题困扰了我很久。
$str="<p>
hello<br>
world
</p>";
//$str=str_replace("\n","",$str);
$str=preg_replace("@\n@","",$str);
//$str=preg_replace("@\s+@"," ",$str);
echo $str;
【问题讨论】:
-
试试nl2br()
标签: php