问题
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