Reputation: 59
Hey I am trying to get viewers from XML file. Problem is in path cuz other paths were working for me. I guess problem is because it's element? <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;
Upvotes: 0
Views: 66
Reputation: 163577
You could get the views by using instead of using ->attributes('statistics')
use the statistics property first, and from that, get the views from the attributes:
->statistics->attributes()->views;
The code could look like:
$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;
Output
131
Upvotes: 1