Return to Snippet

Revision: 12555
at March 18, 2009 18:43 by iTony


Initial Code
function resizeMarkup($markup, $dimensions) 
{ 
    $w = $dimensions['width']; 
    $h = $dimensions['height']; 
     
    $patterns = array(); 
    $replacements = array(); 
    if( !empty($w) ) 
    { 
        $patterns[] = '/width="([0-9]+)"/'; 
        $patterns[] = '/width:([0-9]+)/'; 
         
        $replacements[] = 'width="'.$w.'"'; 
        $replacements[] = 'width:'.$w; 
    } 
     
    if( !empty($h) ) 
    { 
        $patterns[] = '/height="([0-9]+)"/'; 
        $patterns[] = '/height:([0-9]+)/'; 
         
        $replacements[] = 'height="'.$h.'"'; 
        $replacements[] = 'height:'.$h; 
    } 
     
    return preg_replace($patterns, $replacements, $markup);  
}

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

Initial Description

                                

Initial Title
dynamically change dimensions in HTML markup

Initial Tags

                                

Initial Language
PHP