$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $realhost);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $regstring);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,180);
$arg1=curl_exec($ch);
if($queue_debug_mode=="1"){echo "Debug (".curl_error($ch)."): ";print_r(htmlentities($arg1));}
curl_close($ch);
print_r($arg1);输出结果为:
[RESPONSE]
code = 541
description = Command failed
reason = Nameserver requeired.请问怎么把curl_exec的结果转化为array(),我可以这样使用$response["code"]或者$response["description"]

解决方案 »

  1.   

    我自己想到方法了
    $response=array();
    $output = explode("\n",$arg1);
    foreach($output as $val)
    {
    $tmp=@explode("=",$val);
    if(count($tmp)>1)
     {
        $response[trim($tmp[0])]=trim($tmp[1]);
     }
    }
      

  2.   

    如果你能改$realhost,最好输出成HTTP请求GET传递参数的形式,一般的接口都是这样的形式,形如:
    param1=value1&param2=value2....
    这样直接用parse_str就可以了