Friday, 17 June 2016

How to get youtube video ID from url using php?

Here’s a handy PHP code snippet which allows you to extract the video ID of a YouTube video from URL. All you need to do is 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 output,
y2Ky3Wo37AY

0 comments:

Post a Comment