iframe de um vídeo do youtube e/ou vimeo.
<?php
function iframeVideoUrl($url, $width = 640, $height = 360){
if( strpos($url, 'vimeo') ){
$url_parts = explode('/', $url);
foreach ($url_parts as $value) {
if( ! is_numeric($value) )
continue;
$id = $value;
}
$iframe = sprintf('<iframe width="%s" height="%s" src="http://player.vimeo.com/video/%s?title=0&byline=0&portrait=0&badge=0&color=ffffff" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>', $width, $height, $id);
} else if( strpos($url, 'youtube') ){
preg_match(
'/[\\?\\&]v=([^\\?\\&]+)/',
$url,
$matches
);
$id = $matches[1];
$iframe = sprintf('<iframe width="%s" height="%s" src="//www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>', $width, $height, $id);
} else {
$iframe = 'O vídeo não pertence ao Youtube e/ou Vimeo.';
}
return $iframe;
}
// Exemplo de uso
echo iframeVideoUrl('https://www.youtube.com/watch?v=sg3LO56gG4U', 500, 400); // Os tamanhos são opcionais