-
-
Save rubo77/6815165 to your computer and use it in GitHub Desktop.
The original Ghist didn't sent the correct result if an empty string is sent to the function.
My edit sends an empty array as the original parse_str
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* do the same than parse_str without max_input_vars limitation | |
* @param $string array string to parse | |
* @return array query parsed | |
**/ | |
function my_parse_str($string) { | |
if($string==='') return array(); | |
$result = array(); | |
// find the pairs "name=value" | |
$pairs = explode('&', $string); | |
$toEvaluate = ''; // we will do a big eval() at the end not pretty but simplier | |
foreach ($pairs as $pair) { | |
list($name, $value) = explode('=', $pair, 2); | |
$name = urldecode($name); | |
$value = urldecode($value); | |
// If the value is a number, set as a number, otherwise escape double quotes and surround in double quotes | |
if (!is_numeric($value)) { | |
$value = '"' . str_replace('"', '\"', $value) . '"'; | |
} | |
if (strpos($name, '[') !== false) { // name is an array | |
$name = preg_replace('|\[|', '][', $name, 1); | |
$name = str_replace(array('\'', '[', ']'), array('\\\'', '[\'', '\']'), $name); | |
$toEvaluate .= '$result[\'' . $name . ' = ' . $value . '; '; // $result['na']['me'] = 'value'; | |
} else { | |
$name = str_replace('\'', '\\\'', $name); | |
$toEvaluate .= '$result[\'' . $name . '\'] = ' . $value . '; '; // $result['name'] = 'value'; | |
} | |
} | |
eval($toEvaluate); | |
return $result; | |
} | |
$array = my_parse_str($query); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this script to circumvent the max_input_vars limit of PHP:https://gist.github.com/rubo77/6815945