Skip to content

Instantly share code, notes, and snippets.

@nciske
Created August 24, 2012 14:58
Show Gist options
  • Save nciske/3451669 to your computer and use it in GitHub Desktop.
Save nciske/3451669 to your computer and use it in GitHub Desktop.
Parse YouTube Video ID from url
// http://stackoverflow.com/questions/2936467/parse-youtube-video-id-using-preg-match
function my_get_youtube_videoid( $url ){
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
return $match[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment