Last active
August 29, 2015 14:04
-
-
Save morales2k/d60997e7b88bbbf8e0c8 to your computer and use it in GitHub Desktop.
Youtube regex to extract video id from most youtube urls... from stack overflow answer: http://stackoverflow.com/a/17030234/1591301
This file contains hidden or 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
$yturl = 'http://youtu.be/0f4qZkd4npM'; | |
/* | |
other possible urls... | |
youtube.com/v/vidid | |
youtube.com/vi/vidid | |
youtube.com/?v=vidid | |
youtube.com/?vi=vidid | |
youtube.com/watch?v=vidid | |
youtube.com/watch?vi=vidid | |
youtu.be/vidid | |
youtube.com/embed/vidid | |
http://youtube.com/v/vidid | |
http://www.youtube.com/v/vidid | |
https://www.youtube.com/v/vidid | |
youtube.com/watch?v=vidid&wtv=wtv | |
http://www.youtube.com/watch?dev=inprogress&v=vidid&feature=related | |
*/ | |
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $yturl, $possible_id); | |
echo "<pre>"; print_r($possible_id); echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment