Extract youtube ID from youtube URL in PHP

Today I will show you a very easy way to Extract youtube ID from youtube URL in PHP. This is very simple task what shouldn’t take time but we usually do it not official with all of situations.

YouTube-Content-ID

It ‘s very simple, you just need to run this wayway

function getIDFromYoutubeURL($url){
        $video_id = false;
        if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
            $video_id = $match[1];
        }
        return $video_id;
    }

Now let ‘s use function like this

$youtubeID = getIDFromYoutubeURL("https://www.youtube.com/watch?v=_URzW7CH8Dg");

// $youtubeID = _URzW7CH8Dg

 

CDN by MaxCDN