仅使用 PHP 显示来自 RSS 源的图像

发布于 2024-10-10 17:00:10 字数 335 浏览 0 评论 0原文

我正在尝试解析 RSS 提要以仅显示图像。我正在使用通用的 wordpress feed,并且想删除所有不是图像的内容。

我一直在尝试 simplepie ,但一直无法找到仅显示图像的可靠方法。

我找到了这个旧的 simplepie 论坛帖子(http://simplepie.org/support/viewtopic.php?id=643),但无法使代码正常工作。我想它现在可能已经过时了,但我不确定。

我不依赖于 simplepie,但确实需要在 php 中工作并输出 html。任何帮助将不胜感激!

I'm attempting to parse an rss feed to display images only. I am using a generic wordpress feed and would like to strip out everything that isn't an image.

I've been playing around with simplepie and but haven't been able to find a solid way to display images only.

I found this old simplepie forum post (http://simplepie.org/support/viewtopic.php?id=643) but was unable to get the code working. I suppose it may just be outdated by now but am unsure.

I'm not tied to simplepie but do need to work within php and output html. Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

痴意少年 2024-10-17 17:00:10

或者类似的东西:

$xml = simplexml_load_file($xml_file_path);
$imgs = $xml->xpath('/rss/channel/image');
foreach($imgs as $image) {
    echo $image->url;
}

Or something like:

$xml = simplexml_load_file($xml_file_path);
$imgs = $xml->xpath('/rss/channel/image');
foreach($imgs as $image) {
    echo $image->url;
}
梦开始←不甜 2024-10-17 17:00:10

查看 SimpleXML

使用它和 xpath 应该可以满足您的需求。

$feed = simplexml_load_file('foo.xml');

foreach ($feed->xpath('//img') as $imgnode) {
   // ...
}

Check out SimpleXML.

Using it and xpath should get you what you need.

$feed = simplexml_load_file('foo.xml');

foreach ($feed->xpath('//img') as $imgnode) {
   // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文