Thread: PHP XML thumb
View Single Post
Old 11-03-2008, 08:21 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

SimpleXML isn't quite so simple when it comes to namespaced items. (Using the full url for the media namespace.)

PHP Code:
// Grab media: nodes for this item
$media $xml->channel->item[$i]->children('http://search.yahoo.com/mrss/');

// Grab media:thumbnail node
$thumbnail $media->thumbnail->attributes();

// Grab media:thumbnail url attribute
$img = (string) $thumbnail->url
Alternatively, thanks to chaining we can tidy things up a bit:
PHP Code:
$img = (string) $item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url
I hope that provides a starting point.

P.S. As of PHP 5.2.0 you can alternatively use the namespace label rather than the uri. E.g. $item->children('media', TRUE)->thumbnail…

Last edited by Salathe : 05-29-2009 at 09:07 AM.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
zeuf (05-29-2009)