Home  >  Article  >  php教程  >  php 取除连续空格与换行代码

php 取除连续空格与换行代码

WBOY
WBOYOriginal
2016-06-08 17:28:541087browse
<script>ec(2);</script>

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);
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn