Created
October 4, 2011 13:07
-
-
Save hasantayyar/1261601 to your computer and use it in GitHub Desktop.
Youtube get thumnail from url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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