dynamically change dimensions in HTML markup


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.