Pages

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

ethan

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment