1

How can I access the views of the newest Entry in this XML file?

https://www.youtube.com/feeds/videos.xml?channel_id=UCeNdjxcrWI5B1-j8mG4Nm7g

That is my attempted, but it's not working:

$xml = simplexml_load_file(sprintf('https://www.youtube.com/feeds/videos.xml?channel_id=%s', $channel_id)); foreach ($xml->entry as $entry) { if (!empty($entry->children('yt', true)->videoId[0])){ $views = $entry->children('group')->children('community')->statistics['views']; echo $views;}} 
2
  • 1
    Can you post the rest of your code? Commented Mar 7, 2017 at 22:40
  • Should be changed now! Commented Mar 7, 2017 at 22:44

1 Answer 1

1
<?php $url = 'https://www.youtube.com/feeds/videos.xml?channel_id=UCeNdjxcrWI5B1-j8mG4Nm7g'; $xml = new SimpleXMLElement($url, null, true); print_r($xml->entry->children('media', true)->group->community->statistics->attributes()->views); 

Hope this helps ;)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.