Skip to content

Instantly share code, notes, and snippets.

@Lotuashvili
Created October 5, 2014 12:59
Show Gist options
  • Save Lotuashvili/ee80a5fb6339d9ad8bac to your computer and use it in GitHub Desktop.
Save Lotuashvili/ee80a5fb6339d9ad8bac to your computer and use it in GitHub Desktop.
filterYoutubeURL
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