Created
July 10, 2015 18:54
-
-
Save saxap/dfddcc455877cbc83605 to your computer and use it in GitHub Desktop.
parse youtube url and return video 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
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