PHP过滤非法字符
class class_replace
{
function htmldecode($str)
{
if(empty($str)) return;
if($str=="") return $str;
$str=str_replace("&"," ",$str);
$str=str_replace(">"," ",$str);
$str=str_replace("<"," ",$str);
$str=str_replace("chr(32)"," ",$str);
$str=str_replace("chr(9)"," ",$str);
$str=str_replace(chr(34)," ",$str);
$str=str_replace("\""," ",$str);
$str=str_replace(chr(39)," ",$str);
$str=str_replace("
"," ",$str);
$str=str_replace("'"," ",$str);
$str=str_replace("select"," ",$str);
$str=str_replace("join"," ",$str);
$str=str_replace("union"," ",$str);
$str=str_replace("where"," ",$str);
$str=str_replace("insert"," ",$str);
$str=str_replace("delete"," ",$str);
$str=str_replace("update"," ",$str);
$str=str_replace("like"," ",$str);
$str=str_replace("drop"," ",$str);
$str=str_replace("create"," ",$str);
$str=str_replace("modify"," ",$str);
$str=str_replace("rename"," ",$str);
$str=str_replace("alter"," ",$str);
$str=str_replace("cas"," ",$str);
$str=str_replace("replace"," ",$str);
$str=str_replace("%"," ",$str);
$str=str_replace("or"," ",$str);
$str=str_replace("and"," ",$str);
$str=str_replace("!"," ",$str);
$str=str_replace("xor"," ",$str);
$str=str_replace("not"," ",$str);
$str=str_replace("user"," ",$str);
$str=str_replace("||"," ",$str);
$str=str_replace("<"," ",$str);
$str=str_replace(">"," ",$str);
return $str;
}
}
?>
使用方法:
$guolv=new class_replace(); //实例化
$username=$guolv->htmldecode($_POST["username"]); //使用例子
class class_replace
{
function htmldecode($str)
{
if(empty($str)) return;
if($str=="") return $str;
$str=str_replace("&"," ",$str);
$str=str_replace(">"," ",$str);
$str=str_replace("<"," ",$str);
$str=str_replace("chr(32)"," ",$str);
$str=str_replace("chr(9)"," ",$str);
$str=str_replace(chr(34)," ",$str);
$str=str_replace("\""," ",$str);
$str=str_replace(chr(39)," ",$str);
$str=str_replace("
"," ",$str);
$str=str_replace("'"," ",$str);
$str=str_replace("select"," ",$str);
$str=str_replace("join"," ",$str);
$str=str_replace("union"," ",$str);
$str=str_replace("where"," ",$str);
$str=str_replace("insert"," ",$str);
$str=str_replace("delete"," ",$str);
$str=str_replace("update"," ",$str);
$str=str_replace("like"," ",$str);
$str=str_replace("drop"," ",$str);
$str=str_replace("create"," ",$str);
$str=str_replace("modify"," ",$str);
$str=str_replace("rename"," ",$str);
$str=str_replace("alter"," ",$str);
$str=str_replace("cas"," ",$str);
$str=str_replace("replace"," ",$str);
$str=str_replace("%"," ",$str);
$str=str_replace("or"," ",$str);
$str=str_replace("and"," ",$str);
$str=str_replace("!"," ",$str);
$str=str_replace("xor"," ",$str);
$str=str_replace("not"," ",$str);
$str=str_replace("user"," ",$str);
$str=str_replace("||"," ",$str);
$str=str_replace("<"," ",$str);
$str=str_replace(">"," ",$str);
return $str;
}
}
?>
使用方法:
$guolv=new class_replace(); //实例化
$username=$guolv->htmldecode($_POST["username"]); //使用例子
作者:noel@淘宝网女装新款秋装连衣裙裤子外套上衣_2012时尚女装新款 Ecmall二次开发-PHP技术
地址:http://www.laohucheng.com/post/134/
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
PHP5文件上传
ASP对特殊字符的过滤
2009
13:39
796
0


