菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

代码解决方案: 在帝国CMS中,可以使用自定义函数来过滤字符。以下是一个示例代码,演示如何使用自定义函数过滤字符: ``` php // 定义一个自定义函数,用于过滤字符 function filt

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:帝国cms教程 帝国CMS函数 帝国CMS过滤 Discuz视频模板 过滤函数

在帝国CMS中,自定义函数过滤字符的代码如下: ```php function filter_char($str) { $str = str_replace("'", "''", $str); // 将单引号替换为两个单引号 $str = str_replace('"', '""', $str); // 将双引号替换为两个双引号 return $str; } ``` 这个函数接收一个字符串参数`$str`,然后将其中的单引号和双引号分别替换为两个单引号和两个双引号,以避免SQL注入等安全问题。

首先在 e/class/connect.php 文件中加入一个自定义函数 比如 NoHTML() 这个自己喜欢随便设置

//去除HTML标记functionNoHTML($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><ahref="[!--titleurl--]">[!--title--]</a></strong><p>[!--smalltext--]</p></li>';

这样问题就解决了,很简单吧。

相关文章

    无相关信息
评论
建站知识
建站知识
使用技巧
调试安装
运营推广