加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

PHP 提交过滤函数用法

发布时间:2020-05-25 06:11:17 所属栏目:PHP 来源:互联网
导读:PHP 提交过滤函数用法

对PHP提交过滤函数感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编两巴掌来看看吧!


/**
* PHP提交过滤函数
*
* @param 
* @arrange 512-笔记网: jb51.cc
**/
function filter($text)
{
//完全过滤注释
$text = preg_replace('/<!--?.*-->/','',$text);
//完全过滤js
$text = preg_replace('/<script?.*/script>/',$text);
//过滤危险的属性,如:过滤on事件lang js
while (preg_match('/(<[^><]+)( lang|action|background|codebase|dynsrc|lowsrc)[^><]+/i',$text,$mat)) {
$text = str_replace($mat[0],$mat[1],$text);
}
while (preg_match('/(<[^><]+)(window.|javascript:|js:|about:|file:|document.|vbs:|cookie)([^><]*)/i',$mat[1] . $mat[3],$text);
}
//过滤多余html
$text = preg_replace('/</?(html|head|meta|link|base|basefont|body|bgsound|script|form|iframe|frame|frameset|applet|id|ilayer|layer|name|script|xml)[^><]*>/i',$text);
//反转换
$text = str_replace('[','<',$text);
$text = str_replace(']','>',$text);
$text = str_replace('|','"',$text);
return $text;
}
/***   来自脚本之家 jb51.cc(jb51.cc)   ***/

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读