html - PHP使用XMLReader解析xml字符串失败,输出为空
迷茫
迷茫 2017-04-11 09:48:13
0
1
885
    /* 发送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 "<br/>------------------------------------";
    /* 转换编码*/
    $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;

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
洪涛

已解决,原因是 XML格式字符串前有空格,导致解析失败.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template