note 109669 added to function.parse-str

From: Date: Tue, 07 Aug 2012 18:35:25 +0000
Subject: note 109669 added to function.parse-str
Groups: php.notes 
Request: Send a blank email to php-notes+get-189948@lists.php.net to get a copy of this message
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); ---- Server IP: 69.147.83.197 Probable Submitter: 189.83.106.118 ---- Manual Page -- http://www.php.net/manual/en/function.parse-str.php Edit -- https://master.php.net/note/edit/109669 Del: integrated -- https://master.php.net/note/delete/109669/integrated Del: useless -- https://master.php.net/note/delete/109669/useless Del: bad code -- https://master.php.net/note/delete/109669/bad+code Del: spam -- https://master.php.net/note/delete/109669/spam Del: non-english -- https://master.php.net/note/delete/109669/non-english Del: in docs -- https://master.php.net/note/delete/109669/in+docs Del: other reasons-- https://master.php.net/note/delete/109669 Reject -- https://master.php.net/note/reject/109669 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189948) next »