使用 PHP 解析 WordPress RSS:I/O 警告:无法加载外部实体
我正在尝试从 PHP 解析 WordPress RSS 提要。以下内容在我的本地服务器上运行良好,但不适用于我的网站实际所在的主机。
<代码>
$url = "../blog/feed/";
$rss = simplexml_load_file($url);
foreach ($rss->频道->item as $item)
{
//做事
}
然而,在我的网站托管的服务器上,我收到错误“I/O 警告:无法加载外部实体”。
但有趣的是,每当我手动将 RSS 文件保存为 xml 文件并指向该文件时,一切正常美好的。因此,虽然我可以在每次发布帖子后手动保存和上传 xml 文件,但我宁愿将其自动化。
我非常感谢您的宝贵时间。以后可能会跟楼主讨论一下。
I'm attempting to parse a wordpress RSS feed from PHP. The following works fine on my local server, but not with the host my site is actually on.
$url = "../blog/feed/"; $rss = simplexml_load_file($url);foreach ($rss->channel->item as $item) { //Do stuff
}
However, on the server my site is hosted, I get the error "I/O warning : failed to load external entity"
Interestingly enough, though, whenever I manually save the RSS file as an xml file and point to that file, everything works fine. So while I could manually save and upload the xml file after every post I do, I'd rather automate it.
I really appreciate your time. I'll probably talk to the host about it after this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设
../blog/feed/
应该指向一个 URL(可能会被 mod_rewrite 重写)。如果您在脚本内使用相对路径,它们将被视为相对于脚本运行位置的物理(文件系统)路径,而不是相对于浏览器中调用的 URL。
指定以
http://
开头的完整 URL 应该会有所帮助。I assume
../blog/feed/
is supposed to point to an URL (that probably gets rewritten by mod_rewrite).If you use a relative path inside the script, they are going to be treated as physical (filesystem) paths relative to where the script runs, not relative to the URL that is called in the browser.
Specifying a full URL starting with
http://
should help.