Page 1 of 1

about preg_replace

Posted: Tue Jul 20, 2010 4:15 am
by dhirajha
I have situation
$content = ' <input hspace="2" height="133" border="2" align="left" width="350" vspace="2" type="image" src="/userfiles/image/raghab_dhoj_pant(1).jpg">';

the height attribute and width attribute keeps changing. What i want is to fix this height to 150 and the width to 100, this string is a part of the field element of the MySQL database.

can any body suggest what will be the expression in preg_replace()? I can afford to use this separately for the width and height.

Thanks in advance

Re: about preg_replace

Posted: Tue Jul 20, 2010 10:28 pm
by whizzopia
Is this what you want?

Code: Select all

$content = ' <input hspace="2" height="133" border="2" align="left" width="350" vspace="2" type="image" src="/userfiles/image/raghab_dhoj_pant(1).jpg">';
$pattern = array("/(height=\")(\d+)\"/","/(width=\")(\d+)\"/");
$replacement = array("height=\"150\"","width=\"100\"");
$output = preg_replace($pattern,$replacement,$content);
echo $output;