Created
December 18, 2019 11:46
-
-
Save phpfiddle/1f9db6b426681301f265c4cbeba9abba to your computer and use it in GitHub Desktop.
[ Posted by Hiren ] Embed link for youtube and vimeo
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 | |
| $embed = ""; | |
| $thumb = ""; | |
| $url = $resource->video; | |
| if (strpos($url, 'youtube') > 0) | |
| { | |
| $embed = 'https://www.youtube.com/embed/'; | |
| // Now get the 'v=' value & stick on the end | |
| preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $matches); | |
| $v = $matches[1]; | |
| // Final result | |
| $embed = $embed . $v; | |
| $thumb = "https://img.youtube.com/vi/$v/mqdefault.jpg"; | |
| } | |
| elseif (strpos($url, 'vimeo') > 0) | |
| { | |
| $embed = 'https://player.vimeo.com/video/'; | |
| // Now get the last part of the url | |
| $v = substr( strrchr( $url, '/' ), 1 ); | |
| // Final result | |
| $embed = $embed . $v; | |
| $vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$v.php")); | |
| $thumb = $vimeo[0]['thumbnail_medium']; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment