我正在尝试创建一个小应用程序,它只需读取RSS源,然后在页面上布局信息.
我发现的所有说明都让这看起来过于简单,但由于某些原因它只是不起作用.我有以下内容
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);
Run Code Online (Sandbox Code Playgroud)
就是这样,然后在第三行中断,出现以下错误
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.
Run Code Online (Sandbox Code Playgroud)
我在我的设置中打开了allow_url_fopen和allow_url_include但仍然没有.我尝试了多个Feed,结果都是一样的?
我在这里生气
Ama*_*ali 33
simplexml_load_file()将XML文件(磁盘上的文件或URL)解释为对象.你所拥有的$feed是一个字符串.
您有两种选择:
用于file_get_contents()将XML提要作为字符串获取,并使用e simplexml_load_string():
$feed = file_get_contents('...');
$items = simplexml_load_string($feed);
Run Code Online (Sandbox Code Playgroud)使用simplexml_load_file()以下方法直接加载XML Feed :
$items = simplexml_load_file('...');
Run Code Online (Sandbox Code Playgroud)