Resize YouTube Embed Video

22 Apr

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


$embed = '<object width="425" height="344"><param name="movie" value=" v/SOiGqFceMYo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="" 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;


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


Posted by on April 22, 2009 in 1, php


Tags: , , , ,

13 responses to “Resize YouTube Embed Video

  1. How I Lost Thirty Pounds in Thirty Days

    May 3, 2009 at 11:03 pm

    Hi, good post. I have been thinking about this issue,so thanks for sharing. I will certainly be coming back to your blog.

  2. How I Lost Thirty Pounds in Thirty Days

    May 4, 2009 at 1:40 pm

    Hi, nice post. I have been pondering this topic,so thanks for writing. I will definitely be coming back to your posts.

  3. Richy

    May 13, 2009 at 9:57 am

    Thaks you 😉

  4. scott sherman

    June 4, 2009 at 9:13 pm

    Hi Sandeep,

    I came across your blog related to a search I was doing on the AWS site. I have a new web effort that I am beginning to plan. I would like to get more insight into the kind of projects you have worked on, what is your specialties, and, get an idea as to how much you charge.

    I look forward to hearing from you.

    I tried to send you an email via gmail. I am posting here too.


  5. alejandro nogales

    August 5, 2009 at 1:10 pm

    hello Sandeep. i found you, not by Googling you, but because I was looking to resize Flash Videos via CSS (i think JS is more likely the solution).

    and voila, i landed on a page of a dude i know. cool.

  6. UtertyAsted

    November 25, 2009 at 5:36 pm

    Seems like you are a true specialist. Did ya study about the matter? hehe

  7. kiruba

    January 13, 2010 at 5:54 am

    Many more thanks.

  8. The Ghost

    January 19, 2010 at 7:18 pm

    SOOO thankfull! really usefull!

  9. Hampton

    May 21, 2010 at 11:07 pm

    What are your dreams for your children?

  10. Carlos

    July 24, 2010 at 5:12 pm

    Hey, thank you for this function, I just would like to tell you I adapted the function for MODX CMS here’s the link.

  11. Kien Pham

    August 10, 2010 at 4:38 am

    thanks a lot
    It is my need.

  12. John Blankhead

    September 10, 2010 at 4:11 pm

    Thanks it helped me a lot with my site 🙂

  13. DP

    January 12, 2011 at 12:20 pm


    Any idea how we could amend this to retain the ratio after adjusting the width?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: