Jump to content

SimpleXml + Media RSS *SOLVED*


ddeile

Recommended Posts

Hello,

I'm new here, love the site.  Anyway, I've been trying to use the SimpleXml module to parse media rss files.  I'm creating a generic rss parser to pull the <media:thumbnail> out of rss feeds.  I've spent the last few days doing this numerous way, but have been unable to return data.

Here are a few of my recent attempts:

[i]Note: I'm using an rss feed from Flickr in these examples.[/i]

[code]
$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');

foreach($entries->children('http://search.yahoo.com/mrss') as $item)
{
  echo $item->thumbnail->attributes();
}

[/code]

and:

[code]
$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
 
foreach($entries->channel->item as $feeditem)
{
$thumbnail = $feeditem->children('http://search.yahoo.com/mrss')->thumbnail->attributes();
}

[/code]

and:

[code]
$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
 
foreach($entries->channel->item as $feeditem)
{
foreach ($feeditem->children('http://search.yahoo.com/mrss') as $entry)
        {
            echo $entry->thumbnail->attributes();
        }

}
[/code]

Can anyone offer any help or suggestions?
Link to comment
https://forums.phpfreaks.com/topic/21880-simplexml-media-rss-solved/
Share on other sites

try
[code]<?php
$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
$data = $entries->xpath ('channel/item/media:thumbnail');
foreach ($data as $item) {
    echo $item['url'].'<br>';
}
   
?>[/code]
SOLVED!

I forgot to echo out my $thumnail variable in my second example.  Here is the code:

[code]$entries = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne?tags=tokyo&format=rss_200');
 
foreach($entries->channel->item as $feeditem)
{
$thumbnail = $feeditem->children('http://search.yahoo.com/mrss')->thumbnail->attributes();
echo $thumbnail[0];
}[/code]

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.