3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function parseIt($input){ parse_str(preg_replace ("/\s+(\w+\[?\]?)=/", "&$1=", $input), $output); $return = []; foreach ($output as $key => $value){ $value = preg_replace('/^"(.+)"$/', "$1", $value); $return[$key] = $value; } return $return; } $inputs[] = 'i=prd33 foo="really long value"'; $inputs[] = '1=prd33,prd22,prd44 foo="something " else with internal quotes"'; $inputs[] = '1=prd33,prd22,prd44 foo="something \' else with internal quotes\'"'; $inputs[] = 'i[]=prd33 foo="hah" i[]=prd32 bar="neener" i[]=prd31'; foreach ($inputs as $input){ print_r(parseIt($input)); }
based on larmv
Output for 5.4.0 - 7.3.1
Array ( [i] => prd33 [foo] => really long value ) Array ( [1] => prd33,prd22,prd44 [foo] => something " else with internal quotes ) Array ( [1] => prd33,prd22,prd44 [foo] => something ' else with internal quotes' ) Array ( [i] => Array ( [0] => prd33 [1] => prd32 [2] => prd31 ) [foo] => hah [bar] => neener )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/IWCtj on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/IWCtj on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/IWCtj on line 5
Process exited with code 255.