Created
July 2, 2021 06:57
-
-
Save santanup789/1474c7593c0f4926b0f8145659ce6ee0 to your computer and use it in GitHub Desktop.
Get Youtube video thumbnail and title dynamically using video ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$get_yt_url = 'https://www.youtube.com/watch?v=VaSstf9VJGQ'; | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $get_yt_url, $match); | |
$youtube_id = $match[1]; | |
echo "<img src='https://img.youtube.com/vi/$youtube_id/maxresdefault.jpg' alt='$getTitle'>"; | |
//Get youtube video title dynamically | |
echo explode(' - YouTube',explode('</title>',explode('<title>',file_get_contents("https://www.youtube.com/watch?v=$youtube_id"))[1])[0])[0]; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment