Quantcast
Channel: Trying to Parse Only the Images from an RSS Feed - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by lethal-guitar for Trying to Parse Only the Images from an RSS Feed

$
0
0

I don't have much experience with xPath, but you could try the following:

$imgs = $xml->xpath('item//img');

This will select all img-elements which are inside item-elements, regardless if there are other elements inbetween. Removing the leading slash will search for item anywhere in the documet, not just from the root. Otherwise, you'd need something like /rss/channel/item....

As for displaying the images: Just output <img>-tags followed by line-breaks, like so:

foreach($imgs as $image) {    echo '<img src="' . $image->src . '" /><br />';}

The preferred way would be to use CSS instead of <br>-tags, but I think they are simpler for a start.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>