note 109669 deleted from function.parse-str by danbrown

From: Date: Fri, 10 Aug 2012 16:09:12 +0000
Subject: note 109669 deleted from function.parse-str by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189998@lists.php.net to get a copy of this message
Note Submitter: andrey ---- Parsing query with dots. <?php $_SERVER['REQUEST_URI'] = '?client.name=client&client.surname=test&filters[name]=x&filters[value]=y&pagination.c=1&pagination.offset=0'; $collection = array(); $parsed = parse_url($_SERVER['REQUEST_URI']); foreach(explode('&', $parsed['query']) as $offset => $segment){ $fragments = explode('.', $segment); for($i = 0, $k = count($fragments); $i < $k; ++$i){ if(isset($fragments[$i])){ if(strpos($fragments[$i], '=') !== false){ $pieces = explode('=', $fragments[$i], 2); $collection [] = count($pieces) >= 2 && strpos($segment, '.') ? sprintf('[%s]', array_shift($pieces)) : array_shift($pieces); $collection [] = sprintf('=%s&', array_pop($pieces)); } else $collection [] = ($i >= 1) ? sprintf('[%s]', $fragments[$i]) : $fragments[$i]; } } } parse_str(substr(implode($collection), 0, -1), $data); print_r($data);

« previous php.notes (#189998) next »