PHP去除连续的空格和换行符
<?php $str="i am a booknnnnnmoth"; //去除所有的空格和换行符 echo preg_replace("/[s]{2,}/","",$str).'<br>'; //去除多余的空格和换行符,只保留一个 echo preg_replace("/([s]{2,})/","1",$str); ?> PHP去除换行的两种方法 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replace("/s/","",$content); echo $content;