SimpleXML-I/O警告:无法加载外部实体 [英] SimpleXML - I/O warning : failed to load external entity

查看:422
本文介绍了SimpleXML-I/O警告:无法加载外部实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个小型应用程序,该应用程序将简单地读取RSS提要,然后在页面上布置信息.

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.

我已在我的设置中启用了allow_url_fopen和allow_url_include,但仍然没有执行任何操作. 我尝试了多个提要,但最终都得到了相同的结果?

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?

我要在这里生气

推荐答案

simplexml_load_file() XML文件(磁盘上的文件或URL)解释为对象. $feed中的内容是一个字符串.

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.

您有两个选择:

  • 使用file_get_contents()获取XML提要作为字符串,并使用e

  • 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);

  • 使用 simplexml_load_file()直接加载XML feed :

  • Load the XML feed directly using simplexml_load_file():

    $items = simplexml_load_file('...');
    

  • 这篇关于SimpleXML-I/O警告:无法加载外部实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆