zoukankan      html  css  js  c++  java
  • 帝国 标签模板 使用程序代码 去除html标记 并 截取字符串

    在使用帝国标签模板的时候,在需要截取字符串,但是如果设置简介截取字数就会出现前台显示出来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>';

    大功告成。 

  • 相关阅读:
    字典树(Trie)的学习笔记
    kmp学习笔记
    NOIP PJ游记
    Hash学习笔记
    神奇的差分法(内附树状数组的一点扩展)
    DLX算法一览
    A*与IDA*的奇妙之旅
    HDU_2553——n皇后问题,作弊
    HDU_2035——求A^B的最后三位数
    HDU_2034——集合A-B
  • 原文地址:https://www.cnblogs.com/yanzhen/p/2375518.html
Copyright © 2011-2022 走看看