douhuan4699 2014-02-09 16:22 采纳率: 100%
浏览 148
已采纳

SimpleXML - I / O警告:无法加载外部实体

I'm trying to create a small application that will simply read an RSS feed and then layout the info on the page.

All the instructions I find make this seem simplistic but for some reason it just isn't working. I have the following

include_once(ABSPATH.WPINC.'/rss.php');
$feed = file_get_contents('http://feeds.bbci.co.uk/sport/0/football/rss.xml?edition=int');
$items = simplexml_load_file($feed);

That's it, it then breaks on the third line with the following error

Error: [2] simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "<?xml version="1.0" encoding="UTF-8"?> <?xm
The rest of the XML file is shown.

I have turned on allow_url_fopen and allow_url_include in my settings but still nothing. I've tried multiple feeds that all end up with the same result?

I'm going mad here

  • 写回答

4条回答 默认 最新

  • dragon0118 2014-02-09 16:28
    关注

    simplexml_load_file() interprets an XML file (either a file on your disk or a URL) into an object. What you have in $feed is a string.

    You have two options:

    • Use file_get_contents() to get the XML feed as a string, and use e simplexml_load_string():

      $feed = file_get_contents('...');
      $items = simplexml_load_string($feed);
      
    • Load the XML feed directly using simplexml_load_file():

      $items = simplexml_load_file('...');
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 给出完整的python代码并解释
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥15 关于#wpf#的问题:怎么更改LayoutGroup组件的标签页的字体颜色
  • ¥15 中级微观经济学,生产可能性边界问题