Home >Backend Development >PHP Tutorial >PHP多个连续空格回车替换为一个,怎么写更简短

PHP多个连续空格回车替换为一个,怎么写更简短

WBOY
WBOYOriginal
2016-06-13 11:56:061716browse

PHP多个连续空格回车替换为一个,如何写更简短?
php多个连续空格( )或者分段
替换为一个。如何改写下面这个更加简短?

<br /><br />function re($content)<br />{<br />    /* return preg_replace('/(<br\s*\/?>){3,}|( ){3,}/i'),'\\1',$content); */ //错误!<br />    /* return preg_replace('/(<br\s*\/?>| ){3,}/i'),'\\1',$content); */ //错误!<br />    return preg_replace(array('/(<br\s*\/?>){3,}/i','/( ){3,}/i'),'\\1',$content);<br />}<br /><br /><br />//test<br />$content = '1111    <br><br><br><br />@@@<br/><br><br/><br>aaaaM<br><br/>';<br />echo re($content);<br />exit();<br />

------解决方案--------------------
已经很短了,还要改什么呢。

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