parse_str()
Deconstructs a URL query string parsing out the variable/value pairs. The array named as the second parameter will hold all the info. If the second parameter is not present, the variables will be put into the current scope (see extract).
This function is the counterpart of http_build_query().
I advise you to always include the second parameter to avoid overwriting data and to ensure you always know where your data originated from.
$a = 'monkey'; $str = 'a=zebra&b=yak&c=Xavier&0=litmus&1=test&d=whale'; parse_str($str); /* Equivalent to doing the following: $a = 'zebra'; $b = 'yak'; $c = 'Xavier'; $0 = 'litmus'; $1 = 'test'; $d = 'whale'; An error would be thrown if you tried to create the variables $0 and $1 but no error would occur parse_str, though you wouldn't be able to retrieve the values of $0 or $1 here. $a would now hold the value "zebra". */ $str = 'a=zebra&b=yak&c=Xavier&0=litmus&1=test&d=whale'; parse_str($str, $arr); /* $arr is now: array ( 'a' => 'zebra', 'b' => 'yak', 'c' => 'Xavier', 0 => 'litmus', 1 => 'test', 'd' => 'whale' ) Here, you could be able to access all values such as $arr[0] and $arr[1]. */
See the manual entry for parse_str()
