Hello, I'm currently building an RSS feed agregator in php. I am able to obtain, store and display the title, descirption, etc. but haven't been able to obtain images from the xml files. Here is the table structure of a common rss xml file (this one is from yahoo):
<item>
<title>story title</title>
<link>http://story_url</link>
<guid isPermaLink="false">/link/link2</guid>
<source>AP</source>
<pubDate>Mon, 02 Jun 2008 11:20:14 GMT</pubDate>
<description>description goes here</description>
<media:content url="http://imageurl.jpg" type="image/jpeg" height="130" width="111" />
<media:text type="html"><p><a href="linkurl"><img src="http://imageurl.jpg" align="left" height="130" width="111" alt="photo" title="description" border="0"/></a></p><br clear="all"/></media:text>
<media:credit role="publishing company">(AP)</media:credit>
</item>
What i'm interested in is the media:content 'url' variable, which stores the image URL. So far I've got the following code (works fine for title, description and URL):
foreach ($xml->item as $item) {
$rss_feed_title = trim(strval($item->title));
$rss_feed_url = trim(strval($item->link));
$rss_feed_description = trim(strval($item->description));
//try to obtain the image as well (this doesn't work)
$rss_feed_image = trim(strval($item->media['url']));
//insert code here to store the values in a database
}
The problem is this line:
$rss_feed_image = trim(strval($item->media['url']));
which doesn't work. I'm hoping someone can tell me what I'm doing wrong here, and how I would call the 'url' tag from the media:content part of the xml file.
(Edited the first
tags and changed second ones to [code=php] tags -- NogDog)[/i]