If you are struggling to get the video id (i.e.v=id) from YouTube’s URL, use the below function.
function get_youtube_video_id($youtubeUrl) {
preg_match_all("#(?<=v=|v\/|vi=|vi\/|youtu.be\/)[a-zA-Z0-9_-]{11}#", $youtubeUrl, $matches);
$youtubeVideoID = $matches[0][0];
return $youtubeVideoID;
}
$youTubeVideoID = get_youtube_video_id('https://www.youtube.com/watch?v=Zftx68K-1D4');
Views: 124