Created
October 5, 2014 12:59
-
-
Save Lotuashvili/ee80a5fb6339d9ad8bac to your computer and use it in GitHub Desktop.
filterYoutubeURL
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 filterYoutubeURL($url) { | |
if (strpos($url, 'watch?v=') != false) { | |
$url = explode('=', $url); | |
if (strpos($url[1], '&') != false) { | |
$url = explode('&', $url[1]); | |
return $url[0]; | |
} else return $url[1]; | |
} else if (strpos($url, 'youtu.be/') != false) { | |
$url = preg_replace('/http:\/\/youtu.be\//', '', $url); | |
$url = preg_replace('/https:\/\/youtu.be\//', '', $url); | |
$url = preg_replace('/youtu.be\//', '', $url); | |
$url = preg_replace('/\//', '', $url); | |
if (strpos($url, '?') != false) { | |
$url = explode('?', $url); | |
$url = $url[0]; | |
} | |
return $url; | |
} else return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment