Skip to content

Instantly share code, notes, and snippets.

@allanemerson
Created June 20, 2013 23:00
Show Gist options
  • Save allanemerson/5827535 to your computer and use it in GitHub Desktop.
Save allanemerson/5827535 to your computer and use it in GitHub Desktop.
Gets the video ID out of the full youtube url or out of the "share" url.
// Extracts the video ID from a youtube URL
function get_youtube_id($url){
// share URL
if( strstr($url, 'youtu.be/') ){
$id = str_replace('http://youtu.be/', '', $url);
}else{
// full youtube URL
$query_string = array();
parse_str(parse_url($url, PHP_URL_QUERY), $query_string);
$id = $query_string["v"];
}
return $id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment