Vimeo And Youtube
function youtubeVimeoURLtoPlayer($url,$width,$height){
$parsed = parse_url($url);
$hostname = $parsed['host'];
$query = $parsed['query'];
$path = $parsed['path'];
$Arr = explode('v=',$query);
$videoIDwithString = $Arr[1];
$videoID = substr($videoIDwithString,0,11); // 5sRDHnTApSw
$vimeo = preg_match("@vim@",$hostname);
$youtube = preg_match("@youtube@",$hostname);
$youtu_be = preg_match("@youtu.b@",$hostname);
$video_info = array();
//YOUTUBE.COM
if( (isset($videoID)) && (isset($hostname)) && $youtube){
//echo '<iframe width="' . $width . '" height="' . $height . '" src="http://www.youtube.com/embed/' . $videoID . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>';
$video_info['id'] = $videoID;
$video_info['host'] = 'youtube';
return $video_info;
}
//YOUTU.BE
if( (isset($videoID)) && (isset($hostname)) && $youtu_be){
$ArrV = explode('://youtu.be/',$path); // from ID to end of the string
//echo '<iframe width="' . $width . '" height="' . $height . '" src="http://www.youtube.com/embed' . $ArrV[0] . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>';
$video_info['id'] = $videoID;
$video_info['host'] = 'youtube';
return $video_info;
}
//VIMEO.COM
//https://vimeo.com/45980982
if((isset($hostname)) && $vimeo){
$ArrV = explode('://vimeo.com/',$path); // from ID to end of the string
$videoID = substr($ArrV[0],1,9); // to get video ID
$vimdeoIDInt = intval($videoID); // ID must be integer
//echo '<iframe width="' . $width . '" height="' . $height . '" src="http://player.vimeo.com/video/' . $vimdeoIDInt . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
$video_info['id'] = $videoID;
$video_info['host'] = 'vimeo';
return $video_info;
}
}