Skip to content

Instantly share code, notes, and snippets.

@DfKimera
Created April 13, 2012 16:37
Show Gist options
  • Select an option

  • Save DfKimera/2378224 to your computer and use it in GitHub Desktop.

Select an option

Save DfKimera/2378224 to your computer and use it in GitHub Desktop.
/**
* Youtube: Retorna o link do Youtube embedado
* @param string $url
* @return string 'http://www.youtube.com/embed/'.$codigo;
*/
public static function youTubeVideo($url){
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches);
return 'http://www.youtube.com/embed/'.$matches[0];
}
/**
* Youtube: Retorna o thumb do Youtube
* @param String $url
* @return jpg
*/
public static function youTubeThumb($url){
preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches);
return '//i1.ytimg.com/vi/'.$matches[0].'/hqdefault.jpg';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment