I am currently working with PayPals API and want to transform one of its response from a name-value pair to an array.
So far I have used urldecode()
to decode the response to the following:
[email protected]&[email protected]&MOREINFO=lots more info`
What I would like is to have the following:
RECEIVERBUSINESS => '[email protected]'
RECEIVEREMAIL => '[email protected]'
MOREINFO => 'lots more info'
I'm just not quite sure how to get there!
Many browsers automatically encode and decode the URL and the response string. E.g., A space " " is encoded as a + or %20.
Decoding in Javascript can be achieved using decodeURI function. It takes encodeURIComponent(url) string so it can decode these characters. 2. unescape() function: This function takes a string as a single parameter and uses it to decode that string encoded by the escape() function.
parse_str
is what you're looking for:
parse_str('[email protected]&[email protected]&MOREINFO=lots more info', $arr);
/*
print_r($arr);
Array
(
[RECEIVERBUSINESS] => [email protected]
[RECEIVEREMAIL] => [email protected]
[MOREINFO] => lots more info
)
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With