Posted By

browncardigan on 05/13/10


Tagged


Versions (?)

resizeEmbeds


 / Published in: PHP
 

Takes a string of HTML and resizes all of the embed/objects to a specific size. Handy for resizing videos to a specific size.

  1. function resizeEmbeds($html='', $width=400, $height=300) {
  2.  
  3. $objects = explode('</object>', $html);
  4.  
  5. foreach ($objects as $key => $obj) {
  6. if (strstr($obj, '<object')) {
  7. $html_block = explode('<object', $obj);
  8. if (isset($html_block[1])) {
  9. $html_block[1] = preg_replace("/width=\"[0-9]+\"/smi", "width=\"" . $width . "\"", $html_block[1]);
  10. $html_block[1] = preg_replace("/height=\"[0-9]+\"/smi", "height=\"" . $height . "\"", $html_block[1]);
  11. }
  12. $objects[$key] = implode('<object', $html_block);
  13. }
  14. }
  15.  
  16. return implode('</object>', $objects);
  17.  
  18. }

Report this snippet  

You need to login to post a comment.