I’m using this code to import images from a rss news feed.
$source_xml = simplexml_load_file("http://feeds.bbci.co.uk/news/uk/rss.xml");
foreach ($source_xml->channel->item as $rss) {
$namespace = "http://search.yahoo.com/mrss/";
$images = $rss->children($namespace)->thumbnail[1]->attributes();
$image = $images['url'];
echo $image; echo "<br />";
}
The code seems to be working, however at some point in the loop, it just stops! The loop never goes through the whole rss feed. I tried to find out why it stops, but I just don’t seem to get anywhere. Any ideas?
I got error:
Fatal error: Call to a member function attributes() on a non-object in ...$rss->children($namespace)->thumbnail[1]->attributes()is empty for some line and you got fatal error.Try this: