Last active
February 10, 2021 10:28
-
-
Save amilabandara/bca39c9fbfffd5caf810be5892cf0940 to your computer and use it in GitHub Desktop.
Get youtube image url from video url
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 | |
$url = 'https://www.youtube.com/watch?v=DkxMhdtOnKM'; | |
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); | |
$youtube_id = $match[1]; | |
$image_url = 'https://img.youtube.com/vi/'.$youtube_id.'/maxresdefault.jpg'; | |
echo $image_url; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment