Simple function for matching any youtube link and grabbing the ID
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
if (!function_exists('video_id_from_youtube_url')): | |
function video_id_from_youtube_url($source) | |
{ | |
$pattern = '/^(?:(?:(?:https?:)?\/\/)?(?:www.)?(?:youtu(?:be.com|.be))\/(?:watch\?v\=|v\/)?([\w\-]+))/is'; | |
$matches = array(); | |
preg_match($pattern, $source, $matches); | |
if (isset($matches[1])) return $matches[1]; | |
return false; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment