how can i resize this

Discussion in 'Programming' started by mumfry, Mar 19, 2012.

  1. #1
    so i have a string like the one below

    <iframe width="560" height="315" src="http://www.domain.com" frameborder="0" allowfullscreen></iframe>

    what i would like to do is change the width and height attribute on the fly

    what would be the best way to do this

    i would use the string function - str_replace

    str_replace("width="560" height="315"","width="660" height="415"",$code);

    but the width and height isn't always the same

    i could add a bunch of - str_replace to address all the different dimensions that may appear

    str_replace("width="560" height="515"","width="660" height="415"",$code);
    str_replace("width="363" height="115"","width="660" height="415"",$code);
    str_replace("width="760" height="505"","width="660" height="415"",$code);
    str_replace("width="358" height="375"","width="660" height="415"",$code);
    str_replace("width="890" height="315"","width="660" height="415"",$code);

    but that is just ugly... i think there must be a more efficient way than doing it like that

    is there some form of regex or something i can use

    any help would be greatly appreciated

    thanks alot
     
    Solved! View solution.
    mumfry, Mar 19, 2012 IP
  2. #2
    This should work:
    preg_replace("/width=\"(.*?)\"/", "width=\"100\"", $string)
    preg_replace("/height=\"(.*?)\"/", "height=\"100\"", $string)
     
    Arttu, Mar 19, 2012 IP