about preg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dhirajha
Forum Newbie
Posts: 1
Joined: Tue Jul 20, 2010 3:53 am

about preg_replace

Post 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
whizzopia
Forum Newbie
Posts: 8
Joined: Sun Sep 02, 2007 6:17 pm

Re: about preg_replace

Post 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;
Post Reply