You are looking for parse_str()
.
Parses str, as if it is a query string passed through a URL, and sets the variables in the current scope.
For instance:
$str = "first=value&arr[]=foo+bar&arr[]=baz"; parse_str($str); echo $first; // value echo $arr[0]; // foo bar echo $arr[1]; // baz
You can also specify an array to store the results if you do not want to pollute the scope:
parse_str($str, $output); echo $output['first']; // value echo $output['arr'][0]; // foo bar echo $output['arr'][1]; // baz
source share