帝国 标签模板 使用程序代码 去除html标记 并 截取字符串
2020-09-25 09:17:31
帝国CMS
人点赞
在使用帝国标签模板的时候,在需要截取字符串,但是如果设置简介截取字数就会出现前台显示出来html标签的问题。现公布下我的解决方法。1.在 e/class/connect.php 文件中加入自
在使用帝国标签模板的时候,在需要截取字符串,但是如果设置简介截取字数就会出现前台显示出来html标签的问题。现公布下我的解决方法。
function NoHTML($string){
$string = preg_replace("'<script[^>]*?>.*?</script>'si", "", $string);//去掉javascript
$string = preg_replace("'<[\/\!]*?[^<>]*?>'si", "", $string); //去掉HTML标记
$string = preg_replace("'([\r\n])[\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);
return $string;
}
$listtemp='<li><strong><a href="[!--titleurl--]">[!--title--]</a></strong><p>[!--smalltext--]</p></li>';
1.在 e/class/connect.php 文件中加入自定义函数 去除html标记的方法 NoHTML()
//去除HTML标记
function NoHTML($string){
$string = preg_replace("'<script[^>]*?>.*?</script>'si", "", $string);//去掉javascript
$string = preg_replace("'<[\/\!]*?[^<>]*?>'si", "", $string); //去掉HTML标记
$string = preg_replace("'([\r\n])[\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);
return $string;
}
2.列表内容模板代码:
$r[smalltext]=esub(NoHTML($r[smalltext]),200,'......');
$listtemp='<li><strong><a href="[!--titleurl--]">[!--title--]</a></strong><p>[!--smalltext--]</p></li>';
大功告成。
很赞哦! (
)
相关文章
-
无相关信息
830*140广告