Skip to content

Instantly share code, notes, and snippets.

@saxap
Created July 10, 2015 18:54
Show Gist options
  • Save saxap/dfddcc455877cbc83605 to your computer and use it in GitHub Desktop.
Save saxap/dfddcc455877cbc83605 to your computer and use it in GitHub Desktop.
parse youtube url and return video id
function parse_youtube_url($url) {
$pattern = '#^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x';
preg_match($pattern, $url, $matches);
return (isset($matches[1])) ? $matches[1] : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment