Пример #1
0
 static function getParameter($name, $default = null, $preg_match = null, $places = 'ALL')
 {
     $pre = HTTPRequest::__getParameter($name, $places);
     if (!is_array($name)) {
         $name = array($name);
     }
     if (!is_array($pre)) {
         $pre = array();
     }
     $res = array();
     $c_name = count($name);
     for ($i = 0; $i < $c_name; $i++) {
         if ($pre[$i][1] === false || $preg_match && !preg_match($preg_match, $pre[$i][1])) {
             $res[$name[$i]] = $default;
         } else {
             if (!is_string($pre[$i][1])) {
                 $res[$name[$i]] = $pre[$i][1];
             } else {
                 // sanitized
                 $res[$name[$i]] = get_magic_quotes_gpc() ? addslashes($pre[$i][1]) : $pre[$i][1];
                 // encoding ISO 8859-1
                 if (mb_check_encoding($res[$name[$i]], 'UTF-8')) {
                     $res[$name[$i]] = utf8_decode($res[$name[$i]]);
                 }
             }
         }
         if ($res[$name[$i]] == $default) {
             $_GET[$name[$i]] = $default;
         }
     }
     if ($i == 0) {
         return null;
     }
     if (count($res) > 1) {
         return $res;
     }
     $keys = array_keys($res);
     return $res[$keys[0]];
 }