Created
October 20, 2014 12:11
-
-
Save huglester/085b18e56b36750adda6 to your computer and use it in GitHub Desktop.
test
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
function youtube_get_id($url) | |
{ | |
$pattern = | |
'%^# Match any youtube URL | |
(?:https?://)? # Optional scheme. Either http or https | |
(?:www\.)? # Optional www subdomain | |
(?: # Group host alternatives | |
youtu\.be/ # Either youtu.be, | |
| youtube\.com # or youtube.com | |
(?: # Group path alternatives | |
/embed/ # Either /embed/ | |
| /v/ # or /v/ | |
| .*v= # or /watch\?v= | |
) # End path alternatives. | |
) # End host alternatives. | |
([\w-]{10,12}) # Allow 10-12 for 11 char youtube id. | |
($|&).* # if additional parameters are also in query string after video id. | |
$%x' | |
; | |
$result = preg_match($pattern, $url, $matches); | |
if (false !== $result) | |
{ | |
return $matches[1]; | |
} | |
return false; | |
} | |
function vimeo_get_id($url) | |
{ | |
$result = preg_match('/(\d+)/', $url, $matches); | |
if ($result) | |
{ | |
return $matches[0]; | |
} | |
return false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment