Last active
June 18, 2021 00:13
-
-
Save sionex-code/91140e041d0da335934a to your computer and use it in GitHub Desktop.
Videosharing Website Embed Code Generator PHP
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 | |
/* | |
Snippet Name: Embed Code Generator | |
Author: Muhammad Yaser | |
Description: this is simple class that will generate videos embed tags. width and height is not included in iframe tags. | |
you need to use fitvid.js. fitvids is jQuery Plugin this will alow you to auto resize video player in a container. | |
you are allowed to use this file anywhere you want. you are allowed to modify this file without any restriction. | |
you are allowed to use this file in commerical project. | |
Supported filehost: only 7 videosharing website are supported. | |
*/ | |
class GenerateEmbedCode{ | |
function Code($d){ | |
$d = str_replace(' ', '', $d); | |
$cleanedurl = implode('/', array_slice(explode('/', preg_replace('/https?:\/\/|www./', '', $d)), 0, 1)); | |
switch($cleanedurl){ | |
case 'vimeo.com': | |
$url = $d.'/'; | |
$pattern = "/vimeo.com\/(.*?)\//"; | |
preg_match_all($pattern, $url, $matches); | |
$embedurl = $matches[1][0]; | |
return "<iframe src=\"//player.vimeo.com/video/".$embedurl."\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"; | |
break; | |
case 'youtube.com': | |
$url = $d.'/'; | |
$pattern = "/youtube.com\/watch\?v=(.*?)\//"; | |
preg_match_all($pattern, $url, $matches); | |
$embedurl = $matches[1][0]; | |
return "<iframe src=\"//www.youtube.com/embed/".$embedurl."\" frameborder=\"0\" allowfullscreen></iframe>"; | |
break; | |
case 'dailymotion.com': | |
$url = $d; | |
$pattern = "/dailymotion.com\/video\/(.*?)\_/"; | |
preg_match_all($pattern, $url, $matches); | |
$embedurl = $matches[1][0]; | |
return "<iframe frameborder=\"0\" src=\"//dailymotion.com/embed/video/".$embedurl."\" allowfullscreen></iframe>"; | |
break; | |
case 'tune.pk': | |
$url = $d; | |
$pattern = "/tune.pk\/video\/(.*?)\//"; | |
preg_match_all($pattern, $url, $matches); | |
$embedurl = $matches[1][0]; | |
return "<iframe src=\"http://tune.pk/player/embed_player.php?vid=".$embedurl."\" frameborder=\"0\" allowfullscreen scrolling=\"no\"></iframe>"; | |
break; | |
case 'vube.com': | |
$url = $d; | |
$tokens = explode('/', $url); | |
$embedurl = $tokens[sizeof($tokens)-1]; | |
return "<iframe type=\"text/html\" src=\"//vube.com/embed/video/".$embedurl."?autoplay=false&fit=true\" allowfullscreen frameborder=\"0\">"; | |
break; | |
case 'twitch.tv': | |
$url = $d; | |
if (substr($url,0,4) == 'http'){ | |
return "<iframe src=\"".$url."/embed\" frameborder=\"0\" scrolling=\"no\"></iframe>"; | |
} | |
return 'please enter twitch url with http'; | |
break; | |
case 'metacafe.com': | |
$url = $d; | |
$pattern = "/metacafe.com\/watch\/(.*?)\//"; | |
preg_match_all($pattern, $url, $matches); | |
$embedurl = $matches[1][0]; | |
return "<iframe src=\"//www.metacafe.com/embed/".$embedurl."/\" allowFullScreen frameborder=0></iframe>"; | |
break; | |
} | |
return 'video url not supported.'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment