参数过滤方法

/**

 * url解码

 */

public static function urlDecodeDeep($mixedText){

  if(is_array($mixedText)){

    $mixedRet = array();

    if(!empty($mixedText)){

      foreach($mixedText as $key => $value){

        $mixedRet [$Key] = is_array($value) ? self::urlDecodeDeep($value) : rawurldecode($value);

      }

    }

  }else{

    $mixedRet = rawurldecode($mixedText);

  }

  return $mixedRet ;

}

url编码与上面的类似,只是把rawurldecode();换成rawurlencode();

 

/**

 * 对字符串进行转义

 */

public static function addSlashedDeep($mixedInput){

  if(!get_magic_quotes_gpc()){

    $mixedInput = is_array($mixedInput) ? array_map("addSlashedDeep",$mixedInput) : addslashes($mixedInput);

  }

  return $mixedInput;

}

注释:默认地,PHP 对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。所以您不应对已转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。(字符串转义)

stripslashes()(字符串反转义)

array_map — 为数组的每个元素应用回调函数

预定义字符是:

  • 单引号(')
  • 双引号(")
  • 反斜杠(\)
  • NULL

posted on 2017-05-08 14:16  lansedongqing  阅读(423)  评论(0编辑  收藏  举报

导航