1

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!

Colin
  • 267
  • 1
  • 3
  • 8

2 Answers2

2

Or something like:

$xml = simplexml_load_file($xml_file_path);
$imgs = $xml->xpath('/rss/channel/image');
foreach($imgs as $image) {
    echo $image->url;
}
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
  • That did the trick, thank you! Sheesh what was I doing with simplepie SimpleXML is all sorts of awesome – Colin Jan 06 '11 at 19:46
  • it's good for reads, adding nodes, and non structural edits, but if you ever want to remove nodes, you will have to use the PHP DOM classes instead. – dqhendricks Jan 06 '11 at 19:49
0

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) {
   // ...
}
nikc.org
  • 16,462
  • 6
  • 50
  • 83