Saturday, December 6, 2014

Get YouTube Video ID from URL Using PHP

Get a PHP code which provides you to extract the video ID of a YouTube video from URL. For that you need to pass the YouTube URL to the getYouTubeId() function.

//get video id from youtube url

function getYouTubeId($url){
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
return $my_array_of_vars['v'];
}
echo getYouTubeId('https://www.youtube.com/watch?v=y2Ky3Wo37AY');

The Above code will give output,
y2Ky3Wo37AY

0 comments:

Post a Comment