Skip to content

Instantly share code, notes, and snippets.

@hasantayyar
Created October 4, 2011 13:07
Show Gist options
  • Save hasantayyar/1261601 to your computer and use it in GitHub Desktop.
Save hasantayyar/1261601 to your computer and use it in GitHub Desktop.
Youtube get thumnail from url
<?php
function getThumb($url, $size="big") {
$size = (size === null) ? "big" : $size;
$p = "/([\\?&])v=([^&#]*)/i";
// you can use parse_str to get video id
if(preg_match($p,$url,$results)){
$vid = $results[2];
if (size == "small") {
return "http://img.youtube.com/vi/" . $vid . "/2.jpg";
} else {
return "http://img.youtube.com/vi/" . $vid . "/0.jpg";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment