Created
June 20, 2013 23:00
-
-
Save allanemerson/5827535 to your computer and use it in GitHub Desktop.
Gets the video ID out of the full youtube url or out of the "share" url.
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
// Extracts the video ID from a youtube URL | |
function get_youtube_id($url){ | |
// share URL | |
if( strstr($url, 'youtu.be/') ){ | |
$id = str_replace('http://youtu.be/', '', $url); | |
}else{ | |
// full youtube URL | |
$query_string = array(); | |
parse_str(parse_url($url, PHP_URL_QUERY), $query_string); | |
$id = $query_string["v"]; | |
} | |
return $id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment