帝国cms标签模板使用程序代码加入自定义函数 去除html标记并截取字符串

2018-03-2409:54:56网站建设与开发Comments3,278 views字数 993阅读模式

使用帝国标签模板的时候,在需要截取字符串,但是如果设置简介截取字数就会出现前台显示出来html标签的问题。现公布下我的解决方法。本人帝国初次使用者。方法如果弊病 欢迎高手留言评论。忘共同交流文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

帝国 标签模板 使用程序代码 去除html标记 并 截取字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

1.在 e/class/connect.php 文件中加入自定义函数 去除html标记的方法 NoHTML()文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

帝国cms标签模板使用程序代码加入自定义函数 去除html标记并截取字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

 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 }文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

2.列表内容模板代码:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

帝国cms标签模板使用程序代码加入自定义函数 去除html标记并截取字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

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

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

大功告成。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/2390.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/2390.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定