Home >php教程 >php手册 >php:去掉多余的空行

php:去掉多余的空行

WBOY
WBOYOriginal
2016-06-06 19:53:431886browse

?php $str=iamabook\n\n\n\n\nmoth; //去除所有的空和换行符 echopreg_replace(/[\s]{2,}/,,$str).'br'; //去除多余的空和换行符,只保留一个 echopreg_replace(/([\s]{2,})/,\\1,$str); //去除多余的空或换行$text = preg_replace(/(\r\n|\n|\r|\t)/i, '',


$str="i   am    a     book\n\n\n\n\nmoth";
//去除所有的空格和换行符
echo preg_replace("/[\s]{2,}/","",$str).'
';

//去除多余的空格和换行符,只保留一个

echo preg_replace("/([\s]{2,})/","\\1",$str);

//去除多余的空格或换行 $text = preg_replace("/(\r\n|\n|\r|\t)/i", '', $text);

$lastSeveralLineContentsArr = preg_replace("/([ |\t]{0,}[\n]{1,}){2,}/","",$lastSeveralLineContentsArr);//对Html里有连续的空行或tab给正则过滤掉>

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