my code


Resize YouTube or Any Flash Object
by amr.mekkawy

This function change width and height of any YouTube video or any flash object. We can use it to change dimensions of any flash object to fit our design or purposes. I found it in this website

Snippet options

Download: Download snippet as resize-youtube-or-any-flash-object.php.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!


# Creating The Function
function resizeMarkup( $markup, $dimensions ) {
    $w = $dimensions['width'];
    $h = $dimensions['height'];

    $patterns = array();
    $replacements = array();
    if (!empty($w)) {
        $patterns[] = '/width="([0-9]+)"/';
        $patterns[] = '/width:([0-9]+)/';

        $replacements[] = 'width="' . $w . '"';
        $replacements[] = 'width:' . $w;

    if (!empty($h)) {
        $patterns[] = '/height="([0-9]+)"/';
        $patterns[] = '/height:([0-9]+)/';

        $replacements[] = 'height="' . $h . '"';
        $replacements[] = 'height:' . $h;

    return preg_replace($patterns, $replacements, $markup);

# Using the function
$video = '<iframe title="YouTube video player" width="550" height="420" src="" frameborder="0" allowfullscreen></iframe>';
$video = resizeMarkup($video, array('width'=>$width,'height'=>$height));
echo $video;        


Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.