Jump to content

Pulling image from RSS feed


genista

Recommended Posts

All,

I have most of the info I want from rss feeds, but I cannot seem to get anything on the image, here is the full code I am testing:

 

 

<?php
libxml_use_internal_errors(true);
        $RSS_DOC = simpleXML_load_file('http://rss.cnn.com/rss/cnn_topstories.rss');
        
        if (!$RSS_DOC) {
           //Errors    }
        else{
            //setup rss feed
        } 
$RSSimagedetails = $RSS_DOC->channel->image;    
$RSSitem = $RSS_DOC->channel->item[0];
        $item_id     = md5($RSSitem->title);
        //$fetch_date = date("Y-m-j G:i:s"); //NOTE: we don't use a DB SQL function so its database independant
        $item_title = $RSSitem->title;
                //$item_description = $RSSitem->description;
        $item_date  = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate));
        $item_url    = $RSSitem->link;   
                //$item_image = $RSSitem->getElementsByTagName('image')->item(0)->getAttribute('url');
                
                $item_image_src = $RSS_DOC->channel->image->src;
                $item_image_link = $RSS_DOC->channel->image->link;
                $Pubdate = $RSSitem->pubDate;


echo "<p>item_id  = $item_id</p>";
echo "<p>item_title =$item_title</p>";
echo "<p>item_url = $item_url</p>";
echo "<p>iem_image_src = $item_image_src</p>";
echo "<p>item_image_link = $item_image_link</p>";
echo "<img src=\"" . (string)$RSSitem->enclosure['url'][0] . "\">"; 

 

None of the image items are returning anything, any ideas on the best way to pull this out - specifically the url of the image?

Thanks,

G

 

 

Link to comment
https://forums.phpfreaks.com/topic/287182-pulling-image-from-rss-feed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.