Forum Moderators: coopster

Message Too Old, No Replies

Surround section of string with bold tags

         

andrewheiss

9:49 am on Nov 19, 2008 (gmt 0)

10+ Year Member



I'm trying to set up a search system for a database and want to bold the search string that is found in each of the results--if the person searches for "ap" the list would return:
apple
pineapple

I've been trying to figure out how to manage this with str_replace but can't wrap my head around it. I figure I'll probably have to use regular expressions somehow---I just have no idea how to start tackling this.

Thanks!

Anyango

1:38 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?
$str="test test test testing";

$search="st";
$s=str_replace($search,"<b>$search</b>",$str);
echo $s;
?>

andrewheiss

1:48 pm on Nov 19, 2008 (gmt 0)

10+ Year Member



That's a lot easier that what I was trying - I had gotten into preg_replace and some crazy regular expressions.

Thanks!