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

所属分类: CMS教程 / dedecms 阅读数: 2240
收藏 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中七个容易忽略的安全细节介绍

dede也许站长都会用了.但是有不少的细节和经验还是要注意的
收藏 0 赞 0 分享

让Dedecms自带搜索实现全文检索(支持标题与内容)

Dedecms 5.5 5.6默认的模糊搜索只能根据网站文章的名称进行搜索,无法搜索到文章内部信息,下面讲一下如何让Dedecms自带搜索实现全文检索
收藏 0 赞 0 分享

织梦DedeCms v5.6/5.7 新图集页面增加图片下载功能

织梦DedeCms v5.6/5.7 新图集页面增加图片下载功能,其实就是加个右键下载提示功能
收藏 0 赞 0 分享

dedecms5.7sp1评论添加字段的实现方法

有时候我们需要对评论添加字段,让用户更喜欢留言,有类似需要的朋友可以参考下
收藏 0 赞 0 分享

织梦CMS采集时keywords字段无法添加过滤规则的解决方法

有朋友反馈,采集规则编写时,需要对keywords进行剔除,使用 {dede:trim replace=''}(.*){/dede:trim} 过滤规则无效。查看了下,附上解决办法
收藏 0 赞 0 分享

dedecms实现大图showphoto.htm输出图集内容简介方法

dedecms实现大图showphoto.htm输出图集内容简介方法,需要的朋友可以参考下
收藏 0 赞 0 分享

为DedeCMS换上精美多样的提示信息窗口

为DedeCMS换上精美多样的提示信息窗口 用到的开源项目:DedeCMS ,artdialog 步骤
收藏 0 赞 0 分享

DedeCMS Pagetitle 标记使用实例教程

DedeCMS Pagetitle 标记使用实例教程 【Pagetitle 标记】 功能说明:表示获取文档的分页标题 适用范围:仅文档模板
收藏 0 赞 0 分享

织梦DedeCMS实现 三级栏目_二级栏目_一级栏目_网站名称 的效果代码

用这个办法,可以实现
收藏 0 赞 0 分享

dedecms获取文档当前栏目所在目录链接URL

dedecms内容页调用当前栏目其实用下来是调用不出来的,{dede:field.typename/}是有效的,可是 {dede:field.typeurl/}却调不出文档当前栏目所在目录链接URL
收藏 0 赞 0 分享
查看更多