现在的位置: 首页 > 综合 > 正文

php:去掉多余的空行

2014年09月05日 ⁄ 综合 ⁄ 共 365字 ⁄ 字号 评论关闭

<?php
$str="i   am    a     book\n\n\n\n\nmoth";
//去除所有的空格和换行符
echo preg_replace("/[\s]{2,}/","",$str).'<br>';
//去除多余的空格和换行符,只保留一个

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给正则过滤掉>

?>

抱歉!评论已关闭.