织梦dedecms富文本内容中屏蔽标签实例代码

所属分类: CMS教程 / dedecms 阅读数: 2096
收藏 0 赞 0 分享

文章的body字段屏蔽a标签和iframe标签

{dede:field.body runphp="yes"}
    $str=@me;
    @me='';
    $str1='';
    $str1 = preg_replace( "@<iframe(.*?)</iframe>@is", "", $str ); 
    $str1 = preg_replace("/<a[^>]*>(.*?)<\/a>/is", "$1", $str1);
    @me=$str1;
{/dede:field.body}

以下是过滤其他标签的正则表达式

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)
$str=preg_replace("/<\!–.*?–>/si","",$str); //注释
$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(\/?br.*?)>/si","",$str); //过滤br标签
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签
$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,

$str = preg_replace( "@<script(.*?)</script>@is", "", $str ); //过滤script代码
$str = preg_replace( "@<iframe(.*?)</iframe>@is", "", $str );
$str = preg_replace( "@<style(.*?)</style>@is", "", $str );
$str = preg_replace( "@<(.*?)>@is", "", $str ); 

大家可以在本地尝试下小编已经成功了,希望我们整理的内容能够帮助到大家。

更多精彩内容其他人还在看

DedeCMS 5 .7 自定义表单制作和调用办法[图文]

在很多建站需求中,需要一些额外的表单供前台用户提交,以便于收集、统计、分析及处理更多的数据,比如:在线订单、在线报名等一些常见的互动应用
收藏 0 赞 0 分享

dedecms 添加字段后软件列表页无法调用软件大小问题的解决方法

最近做模版想在软件列表页(list_soft.htm)利用[field:softsize/]调用软件大小,才发现原来需要如果解决方法
收藏 0 赞 0 分享

织梦DedeCMS模板防盗的四种方法分享

织梦(DedeCMS)模板也是一种财富,不想自己辛辛苦苦做的模板被盗用,在互联网上出现一些和自己一模一样的网站,就需要做好模板防盗
收藏 0 赞 0 分享

dedecms TAG标签按栏目显示的方法

想让dedecms 的TAG标签按栏目显示
收藏 0 赞 0 分享

dedecms修改按tag标签显示全站相关内容的方法

本文简单的设置就可以把dedecms按tag标签显示全站相关内容
收藏 0 赞 0 分享

dedecms正文自动排版插件 伪原创站必备

为了节约时间,站长可以安装dedecms正文自动排版插件,通过该插件,所有的隐藏代码、链接代码、垃圾代码可以一并删除,统一文章格式,方便简单
收藏 0 赞 0 分享

织梦dedecms 提示 body has not allow words 问题解决

body has not allow words DEDE提示这个是什么意思呢
收藏 0 赞 0 分享

dedecms修改文章自动增加的起始ID从指定数字增加文章ID的方法

dedecms织梦文章系统修改文章自动增加的起始ID从指定数字增加文章ID的方法教给大家
收藏 0 赞 0 分享

dedecms V5.7修改表前缀的方法及出现不显示文章内容的解决方法

将下面的内容保存为 pre.bat 内容可以使用记事本批量替换成你的表前缀和想要改成的前缀. window下的ren命令是重命名的
收藏 0 赞 0 分享

织梦 DeDeCMS 添加自定义属性的方法(图文教程)

由于想在网站首页添加一个本站原创内容的版块.又没办法通过版块id来调用,把每篇原创文章添加副栏目又非常麻烦
收藏 0 赞 0 分享
查看更多