php - Get Youtube data API for thumbnails with SimpleXML -


i have following code:

$rss = simplexml_load_file( 'http://gdata.youtube.com/feeds/api/playlists/plea1736aa2720470c?v=2&prettyprint=true' );  foreach ( $rss->entry $entry ) {     // nodes in media: namespace media information     $media = $entry->children( 'http://search.yahoo.com/mrss/' );     $thumbs = $media->group->thumbnail;     $thumb_attrs = array();     $index = 0;     // thumbnails attributes: url | height | width     foreach ( $thumbs $thumb ) {         foreach ( $thumb->attributes() $attr => $value ) {             $thumb_attrs[$index][$attr] = $value;             print $attr . ': ' . $thumb_attrs[$index][$attr] . "| ";         }         $index++;         print  "<br>";     } } 

the print output:

url: http://i.ytimg.com/vi/te28_l-do88/default.jpg| height: 90| width: 120| time: 00:00:49|  ... 

from xml tags following format:

<media:thumbnail url='http://i.ytimg.com/vi/4l4rwvaphfa/default.jpg' height='90' width='120' time='00:02:23.500' yt:name='default'/> ... 

how can add attribute namespace yt name = 'default' i'm not getting array?

how can closest value of width other value array? similar php - nearest value array taking account array multidimensional.

the problem simplexml , namespaces have access namespaced elements or attributes name -- is, can't say, "give me attributes regardless of namespace." have looping, relying on simplexml's namespacing tools:

$rss = simplexml_load_file( 'http://gdata.youtube.com/feeds/api/playlists/plea1736aa2720470c?v=2&prettyprint=true' ); $namespaces=$rss->getnamespaces(true); // access namespaces used in tree array_unshift($namespaces,""); // add blank @ beginning of array deal unprefixed default foreach ( $rss->entry $entry ) {     // nodes in media: namespace media information     $media = $entry->children( 'http://search.yahoo.com/mrss/' );     $thumbs = $media->group->thumbnail;     $thumb_attrs = array();     $index = 0;     // thumbnails attributes: url | height | width     foreach ( $thumbs $thumb ) {         $attrstring="";         foreach ($namespaces $ns) {                 foreach ( $thumb->attributes($ns) $attr => $value ) { // attributes, whatever namespace might in                         $thumb_attrs[$index][$attr] = $value;                         $attrstring.=$attr . ': ' . $thumb_attrs[$index][$attr] . "| ";                 }         }         print $attrstring;         $index++;         print  "<br>";     } } 

as second part of question, i'm not 100% sure you're asking. if similar question link to, wouldn't able create empty array before loop, , add width of each entry array? when loop done, you'll have flattened array of widths.

but if you're asking else, perhaps can clarify?


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -