很抱歉,里面一个调用错了。
用这个/*
* class slash is used to add or strip slashes in the post,get or cookies strings.
* method:strip ,to strip
* method:add,to add.
*
*/
class slash{
/*
* function strip is to strip the tag in the post ,get or cookies 
* which was added by the system or by add function
*/
function strip()
{
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);        return $value;
    }    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
}
/*
* add is to add slashes to post or get or cookie string,if the magic_quotes_gpc is set as 0,this 
* function will worked.
*/
function add()
{
if (!get_magic_quotes_gpc()) {
$this->add_Slashes(&$_POST);
$this->add_Slashes(&$_GET);
}
}
function add_Slashes($pText) {
if ( is_array($pText) && count($pText) ) {
foreach ($pText as $pKey -> $pVal) {
$pText[$pKey] = $this->add_Slashes($pVal);
}
} else {
$pText=$this->addslashes($pText);
}
return $pText;
}
}

解决方案 »

  1.   

    哦 跟我这样用有什么优势呢?<? 
    # 此为头文件
    define("PHP_MAGIC_GPC", get_magic_quotes_gpc());
    function raddslashes(&$data)
    {
    if(!PHP_MAGIC_GPC)
    {
    return is_array($data) ? array_map('raddslashes',$data) : addslashes($data);
    }
    else
    {
    return $data;
    }
    }
    $_GET = raddslashes($_GET);
    $_POST = raddslashes($_POST);
    ?>
      

  2.   

    hehe将增加标记和去掉标记封装在一个类里,我觉得更好一点。
      

  3.   

    楼主,说点反面的话,先请不要介意,我一直认为,能够使用一个函数完成的简单功能,应该写成一个函数,需要多个函数配合才能完成的复杂功能应该写成一个类。这样才能保证代码可读性和效率之间的平衡。对于这个应用,我比较赞成zhiin(稚鹰)的做法,一个函数就可以了,确实没有必要写成一个类。