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


Decode URL into an array rather than a string

我目前正在使用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'

我只是不太确定怎么去那里!

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

查看explode-

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

http://us.php.net/explode