<?php
$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("/网页特效/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('aabb)
?>
正则表达式中的“原子”
1.a-z A-Z_0_9 //最常见的字符
2.(abc)(akd) //用圆括号抱起来的单元符合
3.[abcs][^abd] //用方括号包含的原子表,原子表中的^代表排除或相反内容
4.转义字符
\d 包含所有数字[0-9]
\D 除所有数字外[^0-9]
\w包含所有英文字符[a-zA-Z]
\W除所有英文字符外[^a-zA-Z]
\s 匹配空格,换行符号等
-----元字符------------
* 可以出现0次或者多次
+ 出现一次或者多次
? 可以出现0次或者一次
. 可以匹配任何内容(处\n 换行符之外)
\b 匹配单词边界,边界可以是空格或者是特殊符号
| 整个单词进行匹配或者整个模块
/^google/ 必须以google开始
/google$/ 必须以google结束
/go(5)gle/ o必须出现5次
/go(5,)gle/ o可以出现5次或者5次以上
/go(2,5)gle/ o出现2-5次