Below is a PHP function that takes in youtube embed code, a desired width and height. It returns the embed code with width and height resized to the desired dimensions.
This is very useful when uploading youtube videos using a CMS or allowing users to upload youtube videos as user generated content.
function resizeYoutubeEmbeddedVideo($embedCode, $width, $height) {
$patterns = array();
$patterns[0] = '/width="(.*?)"/';
$patterns[1] = '/height="(.*?)"/';
$replacements = array();
$replacements[0] = 'width="' . $width . '"';
$replacements[1] = 'height="' . $height . '"';
return preg_replace($patterns, $replacements, $embedCode);
}
Home

Very helpful one…but for some reason it didn’t work for me. It return unchanged values. Did I miss anything?
Plz ignore my previous post. This works like a charm.
Thanks a ton.
Best regards
innIndia
Very nice! Just what I needed.
Thanx for the script. It works like magic.