Decode a URL into an array, not a string

I am currently working with the PayPals API and want to convert one of its responses from a name-value pair to an array.

So far, I have used urldecode() to decode the answer to the following:

 RECEIVERBUSINESS=foo@bar.com & RECEIVEREMAIL=another@email.com &MOREINFO=lots more info` 

I would like to have the following:

 RECEIVERBUSINESS => ' foo@bar.com ' RECEIVEREMAIL => ' another@email.com ' MOREINFO => 'lots more info' 

I'm just not quite sure how to get there!

+6
source share
2 answers

parse_str is what you are looking for:

 parse_str(' RECEIVERBUSINESS=foo@bar.com & RECEIVEREMAIL=another@email.com &MOREINFO=lots more info', $arr); /* print_r($arr); Array ( [RECEIVERBUSINESS] => foo@bar.com [RECEIVEREMAIL] => another@email.com [MOREINFO] => lots more info ) */ 
+16
source

Take a look at explode -

 // poulate array from URL parameters $returnedInfo = explode('&', $dataStringFromUrl); 

http://us.php.net/explode

-2
source

Source: https://habr.com/ru/post/891562/


All Articles