PHP中替换换行符方法总结

<?php
header("content-type:text/html;charset=utf-8");
 $str = "aaaa
 bbbb
 cccc
 dddd";
 echo $str;
 echo '<br/>';
 echo nl2br($str);
 echo '<br/>';

 $str_a = str_replace(array("\r\n","\r","\n"),"",$str);
 echo $str_a;
 echo '<br/>';
 $str_b = str_replace(PHP_EOL,"",$str);
 echo $str_b;
 echo '<br/>';
 $str_c = preg_replace('/\s*/','',$str);
 echo $str_c;
 echo '<br/>';


 ?>

 

posted @ 2016-02-01 10:44  侠岚之弋痕夕  阅读(179)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!