douyao2529 2017-05-20 07:27
浏览 435

Simplexml_load_file():I / O警告:无法加载外部实体“ "

i tried to some the ways load data xml from URL before ask this question but all same failed . Same have some special characters in XML url . this is error

Warning: simplexml_load_file(): I/O warning : failed to load external entity " " in D://....;

And this is my code :

$url = 'http://website.com?xml&param1=1&param2=2';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);    // get the url contents

$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
$json = json_encode($xml);
echo $json;

Thanks every helping

  • 写回答

1条回答 默认 最新

  • doucan8246326 2017-05-20 07:54
    关注

    You could load the URL more simply using

    $context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
    $url = 'http://website.com?xml&param1=1&param2=2';
    
    $xml = file_get_contents($url, false, $context);
    $xml = simplexml_load_string($xml);
    print_r($xml);
    

    Edit: There is some talk about error 403 in various places, one suggestions is to set the user agent prior to this call:

    ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)');
    

    (Taken from file_get_contents() give me 403 Forbidden)

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看