A-A+

PHP用户注册类

2012年02月13日 PHP技术文章 暂无评论 阅读 49 views 次
<?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;
    }
}
?>

<?php
//使用方法:
$guolv=new class_replace(); //实例化
$username=$guolv->htmldecode($_POST["username"]); //使用例子

//这个类来自于互联网,仅供交流使用!

  if(empty($str)) return;
  if($str=="") return $str;

//这两句代码有什么区别,有点不解?

//strip_tags — 过滤全部的HTML标记(包括链接)和PHP标记、JS代码等  
//注册清除:$name = strip_tags($_POST['name']);

//同函数:htmlspecialchars:该函数执行后会把提交数据全部按照文本来展示
?>
标签:

给我留言