Skip to content

Instantly share code, notes, and snippets.

@leafnode
Created September 12, 2015 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leafnode/65e3a5c0615f5a7b25c7 to your computer and use it in GitHub Desktop.
Save leafnode/65e3a5c0615f5a7b25c7 to your computer and use it in GitHub Desktop.
Get YouTube ID from URL
<?php
public static function getYoutubeId($url)
{
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match))
{
return $match[1];
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment