Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode URL into an array rather than a string

Tags:

php

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!

like image 997
lethalMango Avatar asked Jun 28 '11 14:06

lethalMango


People also ask

Does browsers automatically decode URL?

Many browsers automatically encode and decode the URL and the response string. E.g., A space " " is encoded as a + or %20.

How do I decode a URL in typescript?

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.


1 Answers

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
)
*/
like image 175
Tim Cooper Avatar answered Sep 28 '22 01:09

Tim Cooper