lethalMango
lethalMango

Reputation: 4491

Decode URL into an array rather than a string

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!

Upvotes: 11

Views: 10371

Answers (2)

ETWW-Dave
ETWW-Dave

Reputation: 732

Look into explode -

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

http://us.php.net/explode

Upvotes: -3

user142162
user142162

Reputation:

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
)
*/

Upvotes: 22

Related Questions