自定义函数解决帝国cms简介截取字符出现html代码的方法

时间:2023年07月04日

/

来源:网络

/

编辑:佚名

帝国CMS发布信息时,会默认从详情内容中截取前面一段内容作为简介,但有时会截取出html代码,非常不爽,通过本教程可以解决。
首先在 e/class/connect.php 文件中加入一个自定义函数 比如 NoHTML() 这个自己喜欢随便设置
//去除HTML标记 
function NoHTML($string){ 
$string = preg_replace("'<script[^>]*?>.*?</script>'si", "", $string);//去掉javascript 
$string = preg_replace("'<[/!]*?[^<>]*?>'si", "", $string); //去掉HTML标记 
$string = preg_replace("'([rn])[s]+'", "", $string); //去掉空白字符 
$string = preg_replace("'&(quot|#34);'i", "", $string); //替换HTML实体 
$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); 
//以下为屏蔽电话号码正则
$string= preg_replace('/(0[0-9]{2,3}[-]?[2-9])[0-9]{3,4}([0-9]{3}[-]?[0-9]?)/i','$1****$2',$string);//隐藏电话号码中间四位
$string = preg_replace('/(1[358]{1}[0-9])[0-9]{4}([0-9]{4})/i','$1****$2',$string);//隐藏手机号码中间四位
//屏蔽电话号码正则结束
return $string; 
}
全选代码复制
然后去列表内容模板修改代码即可
$r[smalltext]=esub(NoHTML($r[smalltext]),200,'......'); 
$listtemp='<li><strong><a href="[!--titleurl--]">[!--title--]</a></strong><p>[!--smalltext--]</p></li>';
全选代码复制
这样问题就解决了,很简单吧。
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。