如何在字符串中删除"\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;
Run Code Online (Sandbox Code Playgroud)
Ser*_*hiy 19
这也应该可以解决问题.
$str=str_replace("\r\n","",$str);
Run Code Online (Sandbox Code Playgroud)
Hos*_*agh 15
$string = trim(preg_replace('/\s\s+/', ' ', $string));
Run Code Online (Sandbox Code Playgroud)
上面的代码将用一个空格替换多个空格和换行符。
| 归档时间: |
|
| 查看次数: |
26286 次 |
| 最近记录: |