首頁  >  文章  >  CMS教程  >  自訂函數解決帝國cms的簡介截取字元時出現html的問題

自訂函數解決帝國cms的簡介截取字元時出現html的問題

silencement
silencement轉載
2019-11-30 13:46:112360瀏覽

自訂函數解決帝國cms的簡介截取字元時出現html的問題

我的解決方法如下,寫了個函數加進去,大家看看是否可行,有咩有問題,我感覺還行
首先在e/class/connect .php 檔案中加入一個自訂函數例如NoHTML() 這個自己喜歡隨便設定

#程式碼如下:

//去除HTML标记
function NoHTML($string){
$string = preg_replace("&#39;<script[^>]*?>.*?</script>&#39;si", "", $string);//去掉javascript
$string = preg_replace("&#39;<[\/\!]*?[^<>]*?>&#39;si", "", $string); //去掉HTML标记
$string = preg_replace("&#39;([\r\n])[\s]+&#39;", "", $string); //去掉空白字符
$string = preg_replace("&#39;&(quot|#34);&#39;i", "", $string); //替换HTML实体
$string = preg_replace("&#39;&(amp|#38);&#39;i", "", $string);
$string = preg_replace("&#39;&(lt|#60);&#39;i", "", $string);
$string = preg_replace("&#39;&(gt|#62);&#39;i", "", $string);
$string = preg_replace("&#39;&(nbsp|#160);&#39;i", "", $string);
return $string;
}

推薦學習《帝國cms教學

然後去列表內容模板修改程式碼即可

程式碼如下:

$r[smalltext]=esub(NoHTML($r[smalltext]),200,&#39;......&#39;);$listtemp=&#39;<li><strong><a href="[!--titleurl--]">
[!--title--]</a></strong><p>[!--smalltext--]</p></li>&#39;;

這樣問題就解決了,很簡單吧.
由於是中英文的網站,網站名稱需要用到標題,所以這樣修改就很方便了。

以上是自訂函數解決帝國cms的簡介截取字元時出現html的問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:www.word666.com/cms。如有侵權,請聯絡admin@php.cn刪除