How to resize youtube or vimeo movies with PHP

Vimeo Youtube

You have to use the preg_replace php function here. The $video variable holds the embed code fromyoutube, vimeo or other similar website that use these parameters in their embed codes in the example. You can change the width and height in the second parameter. This will replace the width and height parameters in you embed code with you desired width. That way inserted video‘s by users won‘t mess up your layout.

$video = preg_replace('/(width)=("[^"]*")/i', 'width="270"', $video);
$video = preg_replace('/(height)=("[^"]*")/i', 'height="270"', $video);

Comments

Posted on 30-08 by Serp

Greit.

Posted on 04-03 by Suman

For some reason this code not replacing on unix machine please check is this code correct here is original code 2 different <object><object width="640" height="390"><embed src="http://www.youtube.com/v/Yjc1Nvoa32w&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></embed></object></object>

<object style="height:440px; width:540px"><param name="movie" value="http://www.youtube.com/v/KbRKh_454DI?version=3"><embed src="http://www.youtube.com/v/KbRKh_454DI?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object> here is my code from MediaMAx function insert_get_stripped_phrase3($a) { $stripper = $a[details]; $stripper = html_entity_decode($stripper); $stripper = preg_replace('~�*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $stripper); $stripper = preg_replace('~�*([0-9]+);~e', 'chr(\\1)', $stripper); $stripper = preg_replace('/(width):([^"]*")/i', 'width:540px"', $stripper); $stripper = preg_replace('/(height):([^"]*;)/i', 'height:440px;', $stripper); $stripper = preg_replace('/(width)=("[^"]*")/i', 'width="540"', $stripper); $stripper = preg_replace('/(height)=("[^"]*")/i', 'height="440"', $stripper); $stripper = escape_data($stripper); $pos = strpos($stripper, "object"); $pos2 = strpos($stripper, "OBJECT"); if ($pos === false) { $stripper2 = "<object>".$stripper."</object>"; $stripper = $stripper2; } elseif ($pos2 === false) { $stripper2 = "<object>".$stripper."</object>"; $stripper = $stripper2; } return $stripper; }

Leave a comment