如何在此XML文件中访问最新条目的视图?
https://www.youtube.com/feeds/videos.xml?channel_id=UCeNdjxcrWI5B1-j8mG4Nm7g
这是我的尝试,但它不起作用:
$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;}}
答案 0 :(得分: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);
希望这会有所帮助;)