PHP,XML元素路径

PHP,XML元素路径,php,xml,Php,Xml,嘿,我正在尝试从XML文件获取查看器。问题在路径中,因为其他路径对我有效。我想问题是因为它是元素 $url=”https://www.youtube.com/feeds/videos.xml?channel_id=UCH7Hj6l_xDmbyvjQOA5Du0g"; $xml=simplexml\u加载文件($url); $views=$xml->entry[0]->children('media',true)->group[0]->children('media',true)->communi

嘿,我正在尝试从XML文件获取查看器。问题在路径中,因为其他路径对我有效。我想问题是因为它是元素<代码>

$url=”https://www.youtube.com/feeds/videos.xml?channel_id=UCH7Hj6l_xDmbyvjQOA5Du0g";
$xml=simplexml\u加载文件($url);
$views=$xml->entry[0]->children('media',true)->group[0]->children('media',true)->community[0]->children('media',true)->attributes('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