作者:许雅惠嘉文意芝 | 来源:互联网 | 2018-07-16 23:54
ec(2);php取除连续空格与换行代码,这些我们都用到str_replace与正则函数第一种:$contentstr_replace("n","",$content);echo$content;第二种:$contentpreg_replace("s","",$content);ec
php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数
第一种:
$cOntent=str_replace("n","",$content);
echo $content;
第二种:
$cOntent=preg_replace("/s/","",$content);
echo $content;
$str="i am a booknnnnnmoth";
//去除所有的空格和换行符
echo preg_replace("/[s]{2,}/","",$str).'
';
//去除多余的空格和换行符,只保留一个
echo preg_replace("/([s]{2,})/","\1",$str);
?>