Ejemplo n.º 1
0
 /**
 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 = Tool::explode('&', $string);
     $array = array();
     foreach ($parts as $part) {
         list($key, $value) = explode('=', $part);
         $key = urldecode($key);
         $value = urldecode($value);
         if ($specialSyntax && ($matches = self::getSpecialSyntaxKeys($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;
 }