Re: Highlight Search Results

From: Date: Tue, 18 Sep 2012 13:14:04 +0000
Subject: Re: Highlight Search Results
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-319122@lists.php.net to get a copy of this message
On Sep 18, 2012, at 8:42 AM, David OBrien <dgobrien@gmail.com> wrote: > On Tue, Sep 18, 2012 at 8:36 AM, Floyd Resler <fresler@adex-intl.com> wrote: > > > > I want to highlight the word searched in search results. I know I can use str_ireplace to > > do a case insensitive search and replace. However, is there an easy way to maintain the case of the > > word found when I do the replace? > > > > Thanks! > > Floyd > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > function highlight($haystack,$needle) > { > $haystack=preg_replace("/($needle)/i","<span > style='font-weight:bold'>\${1}</span>",$haystack); > return $haystack; > } Perfect! Thanks!

« previous php.general (#319122) next »