I suggest you use JSON output instead of XML code.
You can get it by adding the alt=json parameter to your url:
http://gdata.youtube.com/feeds/api/videos/wGG543FeHOE?v=2&alt=json
Then you need to download json and parse it:
<?php $json_output = file_get_contents("http://gdata.youtube.com/feeds/api/videos/wGG543FeHOE?v=2&alt=json"); $json = json_decode($json_output, true); //This gives you the video description $video_description = $json['entry']['media$group']['media$description']['$t']; //This gives you the video views count $view_count = $json['entry']['yt$statistics']['viewCount']; //This gives you the video title $video_title = $json['entry']['title']['$t']; ?>
Hope this helps.
UPDATE
To find out which variables the JSON output has, add the prettyprint=true parameter to the URL and open it in your browser, it will decorate the JSON output to make it more clear:
http://gdata.youtube.com/feeds/api/videos/wGG543FeHOE?v=2&alt=json&prettyprint=true
Instead of viewing the url you can simply write
echo "<pre>"; print_r($json); echo "</pre>";
after
$json = json_decode($json_output, true);
and it will print formatted JSON output
source share