html - PHP使用XMLReader解析xml字符串失败,输出为空
迷茫
迷茫 2017-04-11 09:48:13
[PHP讨论组]
    /* 发送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;

迷茫
迷茫

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

全部回复(1)
PHP中文网

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号