Posted By

iTony on 03/18/09


Tagged


Versions (?)

dynamically change dimensions in HTML markup


 / Published in: PHP
 

URL: http://ennuidesign.com/blog/ITT+%237%3A+Dynamically+Change+Width+and+Height+in+HTML+Markup/

  1. function resizeMarkup($markup, $dimensions)
  2. {
  3. $w = $dimensions['width'];
  4. $h = $dimensions['height'];
  5.  
  6. $patterns = array();
  7. $replacements = array();
  8. if( !empty($w) )
  9. {
  10. $patterns[] = '/width="([0-9]+)"/';
  11. $patterns[] = '/width:([0-9]+)/';
  12.  
  13. $replacements[] = 'width="'.$w.'"';
  14. $replacements[] = 'width:'.$w;
  15. }
  16.  
  17. if( !empty($h) )
  18. {
  19. $patterns[] = '/height="([0-9]+)"/';
  20. $patterns[] = '/height:([0-9]+)/';
  21.  
  22. $replacements[] = 'height="'.$h.'"';
  23. $replacements[] = 'height:'.$h;
  24. }
  25.  
  26. return preg_replace($patterns, $replacements, $markup);
  27. }

Report this snippet  

You need to login to post a comment.