Jump to content

Pulling image from RSS feed


genista
Go to solution Solved by 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.