/ Published in: PHP
I’ve made this function that receive the input $video string that contains the dirty embed code as it is from youtube. The second parameter $new_width (if specified) permits to resize the embed code proportionally to the width you need for your template. This function removes also unwanted tags added after the important tag (such as happens from Vimeo embeds that have a p tag after the iframe).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function resizeEmbed($video,$new_width='') { if (!$new_width) $new_width = $w; $w2 = $new_width; $ratio = (float)($w2/$w); $h2 = (integer)($h * $ratio); } preg_match_all('@</?\s*(' . $tags . ')(\s+[a-z_]+=(\'[^\']+\'|"[^"]+"))*\s*/?>@i', $i_html, $matches); $full_tags = $matches[0]; $tag_names = $matches[1]; foreach ($full_tags as $i => $full_tag) { if (!in_array($tag_names[$i], $i_allowedtags)) if ($i_trimtext) unset($full_tags[$i]); else $i_html = str_replace($full_tag, '', $i_html); } }
URL: http://www.barattalo.it/2010/10/06/php-function-embed-video-youtube-vimeo/