示例#1
0
文件: Http.php 项目: grithin/phpbase
 /**
 You can have this function include php field special syntax along with standard parsing.
 @param	string	string that matches form of a url query string
 @param	specialSyntax	whether to parse the string using php rules (where [] marks an array) in addition to "standard" rules
 */
 static function parseQuery($string, $specialSyntax = false)
 {
     $parts = \Grithin\Strings::explode('&', $string);
     $array = array();
     foreach ($parts as $part) {
         list($key, $value) = explode('=', $part);
         $key = urldecode($key);
         $value = urldecode($value);
         if ($specialSyntax && ($matches = self::specialSyntaxKeys($key))) {
             if (Arrays::isElement($matches, $array)) {
                 $currentValue = Arrays::getElement($matches, $array);
                 if (is_array($currentValue)) {
                     $currentValue[] = $value;
                 } else {
                     $currentValue = array($currentValue, $value);
                 }
                 Arrays::updateElement($matches, $array, $currentValue);
             } else {
                 Arrays::updateElement($matches, $array, $value);
             }
             unset($match, $matches);
         } else {
             if ($array[$key]) {
                 if (is_array($array[$key])) {
                     $array[$key][] = $value;
                 } else {
                     $array[$key] = array($array[$key], $value);
                 }
             } else {
                 $array[$key] = $value;
             }
         }
     }
     return $array;
 }