把多余的空格去掉
PHP 实现的

解决方案 »

  1.   

    请问楼上知道PHPWind论坛哪些代码是去掉空格的吗?
      

  2.   

    找那段代码找的我头晕
    我自己写的去掉多余空格的代码你参考吧.
    效果见我的网站首页function shorten_filter($a,$b,$c,$d,$e){
    $d = stripslashes($d);
    if($a.$e=='') return $b.$c.$d;
    //保留以下标签两边的空格
    $array = array('font','span','a','label','b','strong','u','i','em','input','button','textarea','select','img');
    if( in_array( strtolower($c),$array) ) return $a.$b.$c.$d.$e;
    return $b.$c.$d;
    }
    function shorten($html){
    $html = preg_replace('/(\s*)(<\/?)(\w+)([^>]*>)(\s*)/mise',"shorten_filter('\\1','\\2','\\3','\\4','\\5');",$html);
    return preg_replace('/(\s{2,})/mise',"(strchr('\\1','\n')?'\n':' ')",$html); //有空格又有换行,保留换行去空格
    }
    ob_start("shorten");