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

所属分类: CMS教程 / dedecms 阅读数: 1962
收藏 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 ); 

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

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

15条实用的预防Dede织梦网站被挂马方法

这篇文章主要介绍了15条实用的预防Dede织梦网站被挂马方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

织梦dedecms默认编辑器实现上传视频功能

这篇文章主要介绍了织梦dedecms默认编辑器实现上传视频功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

织梦dedecms经常被挂马问题的解决方法

网站被挂马是比较常见的网站问题,也是令很多站长比较头痛的问题,因为它会严重影响着网站SEO的优化工作,有可能让你的网站排名在一夜之间回到解放前。那么对于这个问题,今天小编就为大家讲述一下解决的方法
收藏 0 赞 0 分享

dedecms后台文件media_add.php任意上传漏洞的解决方法

一些文件上传接口,同时dedecms对上传文件的后缀类型未进行严格的限制,这导致了黑客可以上传WEBSHELL,获取网站后台权限
收藏 0 赞 0 分享

如何解决织梦dedecms关键词关连文章出错的问题

在本篇文章中小编给大家带来的是关于织梦dedecms关键词关连文章出错的解决办法,有此需要的朋友们可以参考下。
收藏 0 赞 0 分享

在Dede会员投稿增加文章来源功能的方法

在本篇文章中小编给大家带来的是关于在Dede会员投稿增加文章来源功能的方法,有需要的朋友们参考一下。
收藏 0 赞 0 分享

dede首页调用留言本标题的方法总结

这篇文章主要介绍了dede首页调用留言本标题的方法总结,一共3种方法,需要的朋友们可以参考下。
收藏 0 赞 0 分享

如何解决uc服务端地址无效的问题

在本篇文章里小编给大家整理了关于DEDECMS教程:uc服务端地址无效的解决方法,需要的朋友们可以学习下。
收藏 0 赞 0 分享

dedecms自由列表制作Google SiteMap步骤

在本篇文章里小编给大家整理了关于dedecms自由列表制作Google SiteMap步骤和代码,需要的朋友们学习下。
收藏 0 赞 0 分享

dede首页带用户头像调用留言本的实例方法

在本篇文章里小编给大家分享的是关于dede首页带用户头像调用留言本的实例方法,有此需要的朋友们参考下。
收藏 0 赞 0 分享
查看更多