/* 发送curl请求 */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2"); $output = curl_exec($ch); curl_close($ch); print_r($output);echo "
------------------------------------"; /* 转换编码*/ $output = mb_convert_encoding($output, 'UTF-8', 'GB2312'); $output = str_replace('GB2312', 'utf-8', $output); /* 解析xml数据 */ $obj_x = new XMLReader(); $obj_x->XML($output); $res_datas = $this->xml2assoc($obj_x); $obj_x->close(); print_r($res_datas); die;
![](https://img.php.cn/upload/image/000/000/000/b270f644b9d23d2e891d343f8c308a76-0.png)
已解决,原因是 XML格式字符串前有空格,导致解析失败.