php正则过滤html标签、空格、换行符的代码(附说明)
作者:bea
代码如下: $str=preg_replace("/s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格) $str=preg_replace("/<!--.*?-->/si","",$str); //注释 $str=preg_replace("/<(!.*?)>/si","",$str); //过
代码如下:
$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("/<(/?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标签,如javAsCript:alert(
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 为PHP初学者的8点有效建议
- PHP程序员最常犯的11个MySQL错误小结
- Windows 下的 PHP-PEAR 安装方法
- 整理的9个实用的PHP库简介和下载
- Notice: Undefined index: page in E:PHP est.php on line 14
- php运行出现Call to undefined function curl_init()的解决方法
- 《PHP编程最快明白》第八讲:php启发和小结
- 《PHP编程最快明白》第七讲:php图片验证码与缩略图
- 《PHP编程最快明白》第六讲:Mysql数据库操作
- 《PHP编程最快明白》第五讲:php目录、文件操作
- 《PHP编程最快明白》第四讲:日期、表单接收、session、cookie
- 《PHP编程最快明白》第三讲:php数组
- 《PHP编程最快明白》第二讲 数字、浮点、布尔型、字符串和数组
- 一篇有意思的技术文章php介绍篇
- 理解php原理的opcodes(操作码)
- PHP下常用正则表达式整理
- PHP编程最快明白(第一讲 软件环境和准备工作)
- 微盾PHP脚本加密专家php解密算法
- smarty中先strip_tags过滤html标签后truncate截取文章运用