Best way to parse this response into an associative array?
Below is the response I'm getting after posting to an API.... I don't think parse_url is going to cut it. Are there any built in PHP functions or better ways to turn this into an array? This is the output of var_dump
sting(163) "response=3&responsetext=Duplicate transaction REFID:115545335&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=auth&response_code=300&processor开发者_开发知识库_id="
Use parse_str()
with the optional $arr
parameter.
Parses str as if it were the query string passed via a URL
You are looking for parse_str.
It turns a query string into an associative array.
I propose :
$elements = explode('&', $input);
$data = array();
foreach($elements as $e) {
$d = explode('=', $e);
$data[$d[0]] = isset($d[1]) ? $d[1] : '';
}
But maybe there is a better way.
精彩评论