PDA

View Full Version : preg_replace()


Phip
06-24-2002, 05:19 AM
How do i do this in one line.

preg_replace("","<b>",$body);
preg_replace("","</b>",$body);

i want to end up with <b>all the text in between</b>

Jeewhizz
06-24-2002, 09:38 AM
Why do you want to do it in one line?

firepages
06-24-2002, 09:42 AM
basically you dont ;)

never use regex if str_replace will do the same job... str_replace now accepts arrays as arguments...

run this to discover the truth

<?
$str="did I not tell you that ASP rocks the house and all your pages are belong to ASP";

$in=array('','','ASP');
$out=array('<b>','</b>','PHP');
$str=str_replace($in,$out,$str);

echo $str;
?>

root
06-25-2002, 10:52 AM
Good question but why do you want to do that!

cpatzer
07-02-2002, 12:40 AM
preg_replace("","<b>",$body);
preg_replace("","</b>",$body);

This works


$body = "All this text";

Here it is in one line:

$body = preg_replace("/\[bold\](.+?)\[\/bold\]/i","<b>\\1</b>",$body);

Phip
07-02-2002, 02:13 AM
Thank you!