现在的位置: 首页 > 综合 > 正文

帝国 标签模板 使用程序代码 去除html标记 并 截取字符串

2012年06月11日 ⁄ 综合 ⁄ 共 1003字 ⁄ 字号 评论关闭

在使用帝国标签模板的时候,在需要截取字符串,但是如果设置简介截取字数就会出现前台显示出来html标签的问题。现公布下我的解决方法。本人帝国初次使用者。方法如果弊病 欢迎高手留言评论。忘共同交流

帝国 标签模板 使用程序代码 去除html标记 并 截取字符串

1.在 e/class/connect.php 文件中加入自定义函数 去除html标记的方法 NoHTML() 

 

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

2.列表内容模板代码:

 

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

 

大功告成。 

抱歉!评论已关闭.