过滤html在线编辑器产生有危害代码

部分强大的在线编辑器,已经包含了代码整理,过滤功能,但js处理的能被很轻易的饶过,服务端必须要再次过滤一次,这几天花了点时间,写了部分,希望对大家有点用处,本人能力有限,还请有能力的朋友补全它。

 

/*不需要过滤的数组*/
$htm_on=array(
"<acronym","acronym>",
"<baseFont","baseFont>",
"<button","button>",
"<caption","caption>",
"<clientInformation","clientInformation>",
"<font","font>",
"<implementation","implementation>",
"<button","button>",
"<location","location>",
"<option","option>",
"<selection","selection>",
"<strong","strong>",
"font");

$htm_on_uper=array(
"<ACRONYM","ACRONYM>",
"<BASEFONT","BASEFONT>",
"<BUTTON","BUTTON>",
"<CAPTION","CAPTION>",
"<CLIENTINFORMATION","CLIENTINFORMATION>",
"<FONT","FONT>",
"<IMPLEMENTATION","IMPLEMENTATION>",
"<BUTTON","BUTTON>",
"<LOCATION","LOCATION>",
"<OPTION","OPTION>",
"<SELECTION","SELECTION>",
"<STRONG","STRONG>",
"FONT");

/*字符格式*/
$str=strtolower($str);
$str=preg_replace("//s+/", " ", $str);//过滤回车
$str=preg_replace("/ +/", " ", $str);//过滤多个空格

/*过滤/替换几种形式的js*/
$str=preg_replace("/<(script.*?)>(.*?)<(//script.*?)>/si","",$str);//删除<script>。。。</script>格式,
//$str=preg_replace("/<(script.*?)>(.*?)<(//script.*?)>/si","&lt;//1&gt;//2&lt;//3&gt;",$str);//替换为可以显示的,

$str=preg_replace("/<(script.*?)>/si","",$str);//删除<script>未封闭
//$str=preg_replace("/<(script.*?)>/si","&lt;//1&gt;",$str);//替换未封闭

/*删除/替换表单*/
$str=preg_replace("/<(//?form.*?)>/si","",$str);//删除表单
//$str=preg_replace("/<(//?form.*?)>/si","&lt;//1&gt;",$str);//替换表单

$str=preg_replace("/<(i?frame.*?)>(.*?)<(//i?frame.*?)>/si","",$str);//删除框架
//$str=preg_replace("/<(i?frame.*?)>(.*?)<(//i?frame.*?)>/si","&lt;//1&gt;//2&lt;//3&gt;",$str);//替换框架

/*过滤on事件*/
$str=preg_replace("/href=(.+?)([/"|/'| |>])/ie","'href='.strtoupper('//1').'//2'",$str);//把href=涉及到的on转换为大写。
$str=str_replace($htm_on,$htm_on_uper,$str);//把<font,font>换为大写,dhtml标签字符,正则判断太烦琐,采用转换办法。
$str=preg_replace("/(on[^ /.<>]+?)([ |>])/s","//2",$str);//取掉on事件

/*过滤超级连接的js*/
$str=preg_replace("/(href|src|background|url|dynsrc|expression|codebase)[=:/(]([ /"/']*?/w+/..*?|javascript|vbscript:[^>]*?)(/)?)([ >//])/si","//1='#' //3//4",$str);//取掉href=javascript:

//返回小写字符
$str=strtolower($str);
$str=str_replace("&","&#x26;",$str);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值