Read Youtube Feed XML Using PHP

<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>Untitled Document</title>
<script src=”http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js&#8221; type=”text/javascript”></script>
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js&#8221; type=”text/javascript”></script>
<script type=”text/javascript”>
function play(clip){
var mv = “http://www.youtube.com/v/”+clip+”&autoplay=0&rel=0&#8221;;
swfobject.embedSWF(mv, “myContent”, “375”, “295”, “8”);
}
$(document).ready(function() {
play(‘CsGYh8AacgY’);
});
</script>
<style type=”text/css”>
.thumb{
height:150px;
width:150px;
}
</style>
</head>

<body>
<div id=”myContent”></div>
<br />

<B>Choose Video:</B>
<br/>
<?php
//SETTINGS
$channel_name = ‘s4sanjoy’; //Be sure to change this to your channel
$count = 6; //# of videos you want to show (MAX = 20)
$em_width = 420; //width of embedded player
$em_height = 315; //height of embedded player
$wrap_class = ‘video’; //class name for the div wrapper
//The output…
$sxml = simplexml_load_file(“http://gdata.youtube.com/feeds/api/users/$channel_name/uploads?max-results=$count&#8221;);

foreach ($sxml->entry as $entry) {
$vidKey = substr(strrchr($entry->id, ‘/’), 1);
$title = $entry->title;

// get nodes in media: namespace for media information
$media = $entry->children(‘http://search.yahoo.com/mrss/&#8217;);

// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs[‘url’];

// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs[‘url’];

//echo “<a href=# onclick = play(“.$vidKey.”); return false>”.$title.”</a><br/>”;
?>
<img class=”thumb” src=”<?php echo $thumbnail ;?>”>
<br/>
<a href=”#” onclick=”play(‘<?php echo $vidKey ;?>’); return false” style=”color:#9b9898; font-size:12″><?php echo $title ;?></a>
<br/>
<?php
}
?>

</body>
</html>