Created
December 23, 2017 11:43
-
-
Save nilesolutions/a04c0f941a3aeafb67a87a40fc5e919c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Youtube link embed conversion | |
* | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg | |
* | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg | |
* https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg | |
* | |
*/ | |
$video = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","//www.youtube.com/embed/$1", $youtube_link); | |
$thumb = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","//img.youtube.com/vi/$1/maxresdefault.jpg", $youtube_link); | |
// no controls | |
$youtube_embed = preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i","//www.youtube.com/embed/$1?rel=0&controls=0&showinfo=0", $youtube_link); | |
?> | |
<iframe width="100%" height="400" src="<?=$video?>" frameborder="0" allowfullscreen></iframe> | |
<img src="<?=$thumb?>" alt="" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment