Created
July 3, 2012 16:44
-
-
Save banksy89/3040922 to your computer and use it in GitHub Desktop.
Gets the main image for a YouTube image, to be used for a placeholder.
This file contains hidden or 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
function getYouTubeKey ( $video ) | |
{ | |
preg_match ( '#\\?v=([^&]+)\\&#s', $video, $vid ); | |
if ( count ( $vid ) > 0 ) | |
{ | |
// The correct match is the second item in array | |
return $vid[ 1 ]; | |
} | |
else | |
return $video; | |
} | |
$video = 'http://www.youtube.com/watch?v=XlpC8-9iI0A&feature=g-vrec'; | |
<img src="http://img.youtube.com/vi/<?php echo getYouTubeKey ( $video ); ?>/2.jpg" width="663" height="365"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool! Changed and works nicely