Monday, April 20, 2009

Resize YouTube Video

Here is the code how to resize youtube video embed code, even this code will work to non-youtube embed videos.....

<?php

$embed = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/SOiGqFceMYo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/SOiGqFceMYo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';

//$alt = preg_match_all('/(width|height)=("[^"]*")/i', $embed, $matches);

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

echo $embed;

?>

Output here:



Now try to resize youtube player with php regular expression replace preg_replace()......

No comments:

Post a Comment