嘿,我试图从XML文件中获取查看器。问题出在路径中,因为其他路径在为我工作。我猜问题是因为它是要素吗? <media:statistics views="131"/>
$url = "https://www.youtube.com/feeds/videos.xml?channel_id=UCH7Hj6l_xDmbyvjQOA5Du0g";
$xml = simplexml_load_file($url);
$views = $xml->entry[0]->children('media', true)->group[0]->children('media', true)->community[0]->children('media', true)->attributes('statistics');
echo $views;
答案 0 :(得分:1)
您可以通过使用而不是使用->attributes('statistics')
来获取视图,首先使用statistics属性,然后从属性中获取视图:
->statistics->attributes()->views;
代码如下:
$url = "https://www.youtube.com/feeds/videos.xml?channel_id=UCH7Hj6l_xDmbyvjQOA5Du0g";
$xml = simplexml_load_file($url);
$views = $xml->entry[0]->children('media', true)->group[0]->children('media', true)->community[0]->children('media', true)->statistics->attributes()->views;
echo $views;
输出
131