Only show images from an RSS feed with PHP

徘徊边缘 提交于 2019-12-11 12:36:52

问题


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!


回答1:


Or something like:

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



回答2:


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) {
   // ...
}


来源:https://stackoverflow.com/questions/4609380/only-show-images-from-an-rss-feed-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!