Getting the URL of an image from an RSS feed using simplepie

I am very new to php and simplepie. I would like to be able to use simplepie to store the image url for a variable. For my example, I will use the ebay rss feed (http://deals.ebay.com/feeds/rss). The image I'm trying to get the url is in the tag <image src=. When i use code

foreach ($feed->get_items() as $item):
?>
<?php echo $item->get_description(); ?>
<?php endforeach; ?>

The image and description are displayed, but I cannot save the image URL for the variable. How can I use simplepie to store the image url for a variable?

thank

+5
source share
1 answer

You can use the DOM parser, for example SimpleHTML , for example:

require_once('simple_html_dom.php');

foreach ($feed->get_items() as $item)
{
 $description =  $item->get_description();
 $desc_dom = str_get_html($description);
 $image = $desc_dom->find('img', 0);
 $image_url = $image->src;
}

URL- . , , $desc_dom->find('img');

SimpleHTML ,

composer require mgargano/simplehtmldom
+7

All Articles