Helpful Information
 
 
Category: PHP
preg_replace()

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>

Why do you want to do it in one line?

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;
?>

Good question but why do you want to do that!

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);

Thank you!










privacy (GDPR)