php_中替换换行符

//php 有三种方法来解决 
  
//1、使用str_replace 来替换换行 
$str = str_replace(array("\r\n", "\r", "\n"), "", $str); 
  
//2、使用正则替换 
$str = preg_replace('//s*/', '', $str); 
  
//3、使用php定义好的变量 (建议使用) 
$str = str_replace(PHP_EOL, '', $str);
// 转为前台可显示的换行, nl2br 的方向函数参考php手册
$str = "a
b
e
f
c";

echo nl2br($str);

 

posted @ 2015-11-24 20:12  cphmvp  阅读(235)  评论(0编辑  收藏  举报
爬虫在线测试小工具: http://tool.haoshuju.cn/