将URL解码为数组而不是字符串

时间:2011-06-28 14:02:06

标签: php

我目前正在使用PayPals API,并希望将其响应之一从名称 - 值对转换为数组。

到目前为止,我已使用urldecode()解码对以下内容的响应:

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

我想要的是拥有以下内容:

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

我只是不太确定如何到达那里!

2 个答案:

答案 0 :(得分:18)

parse_str正是您所寻找的:

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

答案 1 :(得分:-3)

查看explode -

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

http://us.php.net/explode