Re: Re: Battling with highlighting search criteria
| From: | Erwin | Date: | Mon, 04 Nov 2002 10:02:59 +0000 |
| Subject: | Re: Re: Battling with highlighting search criteria | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122651@lists.php.net to get a copy of this message | ||
>> Try the following one:
>>
>> $result = "This is a test, isn't it?";
>> $search = "is";
>>
>> $result = preg_replace( '/(' . $search . ')/i', "<span
>> class=\"highlight\">\$1</span>", $result );
>>
>>
>> Grtz Erwin
David Russell wrote:
> Hi Erwin,
>
> Yep, this does exactly what str_replace does.
No, it doens't...this one is case insensitive. The pattern (which is
"/(is)/i" in this example), has the i modifier (the last "i"), which means
case insensitive. In fact, the above regexp even preserves case for you!
>
> How can I make the whole thing case insensitive:
It already is, please try it again (I've doublechecked it by now) ;-))
Grtz Erwin