0

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;

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.