用自定義函數(shù)解決帝國(guó)cms的簡(jiǎn)介截取字符時(shí)出現(xiàn)html的問(wèn)題

字號(hào):


    正如標(biāo)題所言帝國(guó)cms的簡(jiǎn)介截取字符時(shí)出現(xiàn)html,針對(duì)這個(gè)問(wèn)題,下面有個(gè)不錯(cuò)的解決方法,主要是通過(guò)自定義函數(shù)來(lái)實(shí)現(xiàn)的,感興趣的朋友也可以嘗試操作下
    首先在 e/class/connect.php 文件中加入一個(gè)自定義函數(shù) 比如 NoHTML() 這個(gè)自己喜歡隨便設(shè)置
    //去除HTML標(biāo)記
    function NoHTML($string){
    $string = preg_replace("'<script[^>]*?>.*?</script>'si", "", $string);//去掉javascript
    $string = preg_replace("'<[/!]*?[^<>]*?>'si", "", $string); //去掉HTML標(biāo)記
    $string = preg_replace("'([rn])[s]+'", "", $string); //去掉空白字符
    $string = preg_replace("'&(quot|#34);'i", "", $string); //替換HTML實(shí)體
    $string = preg_replace("'&(amp|#38);'i", "", $string);
    $string = preg_replace("'&(lt|#60);'i", "", $string);
    $string = preg_replace("'&(gt|#62);'i", "", $string);
    $string = preg_replace("'&(nbsp|#160);'i", "", $string);
    return $string;
    }
    然后去帝國(guó)cms列表內(nèi)容模板修改代碼即可
    $r[smalltext]=esub(NoHTML($r[smalltext]),200,'......');
    $listtemp='<li><strong><a href="[!--titleurl--]">[!--title--]</a></strong><p>[!--smalltext--]</p></li>';
    這樣問(wèn)題就解決了,很簡(jiǎn)單吧.