Skip to content

Instantly share code, notes, and snippets.

@tosinonikute
Created May 12, 2017 10:24
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 tosinonikute/ef6f56f8236f588aa406a8ce66417eeb to your computer and use it in GitHub Desktop.
Save tosinonikute/ef6f56f8236f588aa406a8ce66417eeb to your computer and use it in GitHub Desktop.
function extract_youtube_id($url){
$youtubeid = "";
if (preg_match('/youtube\.com\/watch\?v=([^\&\?\/]+)/', $url, $id)) {
$youtubeid = $id[1];
} else if (preg_match('/youtube\.com\/embed\/([^\&\?\/]+)/', $url, $id)) {
$youtubeid = $id[1];
} else if (preg_match('/youtube\.com\/v\/([^\&\?\/]+)/', $url, $id)) {
$youtubeid = $id[1];
} else if (preg_match('/youtu\.be\/([^\&\?\/]+)/', $url, $id)) {
$youtubeid = $id[1];
} else if (preg_match('/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/', $url, $id)) {
$youtubeid = $id[1];
} else {
$youtubeid = "";
}
return $youtubeid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment