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条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样