parse_str()¶
parse_str() parses a query string and extracts its components, name and value, in an array.
The resulting array uses the names of the variables in the query string as keys, and the value in the query string as values.
parse_str() handles some special conventions: [] turns the variable into an array, including multidimensional arrays and hash. Dots . and spaces `` `` are replaced automatically with underscore _, as they are not allowed in PHP variables. This is a legacy leftover, as no variable is created anymore.
All parsed values are strings or arrays. They may be numeric strings, though.
parse_str() used to allow the second parameter, for the results, to be omitted. Then, it would write the new variables in the current context, with a possible serious security effect. This is not possible anymore since PHP 8.0.
<?php
parse_str("a=1&b[]=3", $array);
print_r($array);
/**
* [a => 1
* b => [
* 3
* ]
* ]
*/
?>
See also RFC-3986.
Related : Parse, Query, http_build_query(), parse_url()