Created
June 24, 2015 23:03
-
-
Save FriendlyWP/3b83b478945436fce6c7 to your computer and use it in GitHub Desktop.
Get YouTube ID from various url structures
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
// GET YOUTUBE ID FROM URL | |
function getYouTubeIdFromURL($url) { | |
$pattern = '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i'; | |
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