Created
October 3, 2016 15:36
-
-
Save vlepeule/1f09cc75b96f3d23f73e0f185cdedc07 to your computer and use it in GitHub Desktop.
Get youtube video ID from URL (regex)
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
<?php | |
$url = "http://your_youtube_video_url"; | |
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches); | |
echo $matches[1]; // The ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment