帝國cms內容頁模板的描述標簽,是直接輸出內容標題,這個在seo優化當中還是有一定影響的,新聞在發布時會自動生成smalltext簡介字段,但我們如果直接在頁面上輸出簡介字段,經常會帶有特殊字符或者帶有換行,這個也是非常不好的。接下來跟cms大學小編一起學習如何在帝國cms的內容頁輸出不換行且沒有特殊字符的內容簡介。
函數代碼如下,:
function Cmsdx_format_html($str){
$str=trim($str);
$str=str_replace('&','',$str);
$str=str_replace('ldquo;','“',$str);
$str=str_replace('rdquo;','”',$str);
$str=str_replace('middot;','·',$str);
$str=str_replace('lsquo;','‘',$str);
$str=str_replace('rsquo;','’',$str);
$str=str_replace('hellip;','…',$str);
$str=str_replace('mdash;','—',$str);
$str=str_replace('ensp;','',$str);
$str=str_replace('emsp;','',$str);
$str=str_replace('nbsp;','',$str);
$str=str_replace(' ','',$str);
$str=str_replace('/t','',$str);
$str=str_replace('/r/n','',$str);
$str=str_replace('/r','',$str);
$str=str_replace('/n','',$str);
$str=str_replace(' ','',$str);
$str = preg_replace('//s(?=/s)/','', $str);// 接著去掉兩個空格以上的
$str = preg_replace('/[/n/r/t]/',' ', $str);// 最后將非空格替換為一個空格
return trim($str);
}
我們將上述函數放到 /e/class/userfun.php 中,這里是存儲用戶的自定義函數。
接下來在內容頁描述的meta標簽中調用如下標簽:
<?=Cmsdx_format_html($navinfor['smalltext'])?>
注意外層一定要包裹我們寫的自定義函數,這樣就可以實現無特殊格式的輸出smalltext簡介字段了。
新聞熱點
疑難解答
圖片精選