XML : Using simplexml_load_file to parse Children Nodes with Namespaces inphp

I am trying to parse this YouTube XML using simplexml_load_file in php.

The XML feed can be found here: https://www.youtube.com/feeds/videos.xml?playlist_id=PL1mm1FfX5EHRjGyoBpEXBRIGAmCNt8pBT

Below in php I am trying to iterate through the media groups nested inside each entry node.

  <?php        $xmlFeed=simplexml_load_file('https://www.youtube.com/feeds/videos.xml?playlist_id=PL1mm1FfX5EHRjGyoBpEXBRIGAmCNt8pBT')      or die("Cannot load YouTube video feed, please try again later.");        foreach ($xmlFeed->entry->children('media', true)->group as $video) {            echo $video->title;          echo $video->description;          echo $video->thumbnail->getNameSpaces(true);        }  ?>    

Title and description print just fine. But I'm trying to get at the thumbnail URL found in this namespace:

  <media:thumbnail url="https://i1.ytimg.com/vi/HEYQXVGnwXc/hqdefault.jpg" width="480" height="360"/>    

I've tried all 3 of the following:

  echo $video->thumbnail->getNameSpaces(true);  echo $video->thumbnail->getNameSpaces(true)['url'];  echo $video->thumbnail->getNameSpaces(true)->url;    

None return the url. The first returns Array and the last two are blank. What am I missing?

No comments:

Post a Comment