使用 PHP 解析 WordPress RSS:I/O 警告:无法加载外部实体

发布于 2024-10-09 22:58:42 字数 456 浏览 0 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-10-16 22:58:42

我假设 ../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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文