note 74061 deleted from function.parse-str by bobby
| From: | bobby@php.net | Date: | Thu, 22 Mar 2007 14:27:57 +0000 |
| Subject: | note 74061 deleted from function.parse-str by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124712@lists.php.net to get a copy of this message | ||
Note Submitter: Jose Luis Castaño Cabrales
Reason: non-english
----
<?php
// Here a new function which doing the same as parse_str for multilevel array
// very funny
// cabrales@web.de
function parseStr($data, &$ret = array()){
if (!is_array($data)){
return false;
};
foreach($data as $v){
if (eregi("(\[|\])", $v)) {
preg_match("#([^\[]+)(\[[^]]+\].*)#", $v, $treffer);
/* treffer[1] has the key 'children' */
$key = $treffer[1];
/* treffer[2] has the rest '[boby][age]=12' */
preg_match("#\[([^\[]+)\](.*)#", $treffer[2], $treffer);
$rest = $treffer[1].$treffer[2];
parseStr(array($key => $rest), $ret[$key]);
}
else {
$v = explode('=', $v);
$ret[$v[0]] = $v[1];
};
};
};
/* Es wird in einem Array umgewandelt */
$queryUrl = trim(urldecode($_SERVER['QUERY_STRING']));
$queryUrl = preg_replace_callback(
"#\&\#(\d+)\;#i",
create_function('$treffer','return chr($treffer[1]);'),
$queryUrl
);
$queryUrl = explode('&', $queryUrl);
parseStr($queryUrl, $result);
print_r($result);
//Saludos from Germany
?>