Created
May 12, 2017 10:24
-
-
Save tosinonikute/ef6f56f8236f588aa406a8ce66417eeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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