How can I turn a string below into an array?
pg_id=2&parent_id=2&document&video
This is the array I am looking for,
array(
'pg_id' => 2,
'parent_id' => 2,
'document' => ,
'video' =>
)
How can I turn a string below into an array?
pg_id=2&parent_id=2&document&video
This is the array I am looking for,
array(
'pg_id' => 2,
'parent_id' => 2,
'document' => ,
'video' =>
)
There are several possible methods, but for you, there is already a builtin
parse_str
functionIf you're having a problem converting a query string to an array because of encoded ampersands
then be sure to use
html_entity_decode
Example:
Using
parse_str()
.Use http://us1.php.net/parse_str
Attention, it's usage is:
not
Sometimes
parse_str()
alone is note accurate, it could display for example:parse_str() would return:
It would be better to combine
parse_str()
withparse_url()
like so:You can use the PHP string function
parse_str()
followed byforeach
loop.