views:

41

answers:

2

Can I automatically resize an embed code efficiently using PHP (maybe with regex?)

Here's an example of the embed code:

<object width="500" height="350">
  <param name="movie" value="http://www.megavideo.com/v/"&gt;&lt;/param&gt;
  <param name="allowFullScreen" value="true"></param>
  <embed src="http://www.megavideo.com/v/" 
     type="application/x-shockwave-flash" 
     allowfullscreen="true"
     width="500" height="350">
  </embed>
</object>
+3  A: 

I think your question is asking how to change the width and height of the <object> tag? If so, if you want to use PHP, you'll have to refresh the page, which you probably don't want to do in this case, since your user will have to reload the video (obviously you would simply output new values to the width and height values).

Instead, you're probably going to want to use JavaScript. Give your object a name, and use JavaScript (with jQuery, etc. if you must) to change the dimensions. This will allow you to change the dimensions without reloading the page.

greg
I just want to change the values before I input it in the database, so that's why I think it'd be best to do it in php once no? Instead of having to do it every time the video is loaded
Belgin Fish
+1  A: 

Do something like

preg_replace('(<[^>]*?)width="[^"]*" height="[^"]*"', '$1width="100" height="200");

(code untested)

thejh