RE: [PHP] Re: Battling with highlighting search criteria

From: Date: Mon, 04 Nov 2002 10:00:29 +0000
Subject: RE: [PHP] Re: Battling with highlighting search criteria
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122650@lists.php.net to get a copy of this message
Sorry, my mistake... This is what happens when you have 2 machines - one production and one development. You get confused between the two <grin> Just one more thing, How can I get the return in the same case as it was originally? Ie if I have $string = "Forward" , and $search = "for", I want <span....>Forward</span>, not <span...>forward</span>. David Russell IT Support Manager Barloworld Optimus (Pty) Ltd Tel: +2711 444-7250 Fax: +2711 444-7256 e-mail: DavidR@BarloworldOptimus.com web: www.BarloworldOptimus.com -----Original Message----- From: David Russell [mailto:DavidR@BarloworldOptimus.com] Sent: 04 November 2002 11:54 AM To: 'Erwin'; php-general@lists.php.net Subject: RE: [PHP] Re: Battling with highlighting search criteria Hi Erwin, Yep, this does exactly what str_replace does. How can I make the whole thing case insensitive: $result= "This Is A Test, Isn't It?" $search= "IS" It will include the 'is' in 'This', and also the 'Is' and the 'is' in 'isn't'. cheers David Russell IT Support Manager Barloworld Optimus (Pty) Ltd Tel: +2711 444-7250 Fax: +2711 444-7256 e-mail: DavidR@BarloworldOptimus.com web: www.BarloworldOptimus.com -----Original Message----- From: Erwin [mailto:erwin@isiz.com] Sent: 04 November 2002 11:27 AM To: php-general@lists.php.net Subject: Re: [PHP] Re: Battling with highlighting search criteria David Russell wrote: > Hey there > > I told you my brain was feeling fuzzy :) > > This works great. Only one problem... I would like it to be case > insensitive... Any way? > > I assume that it would be a ereg/preg replace, but I have no clue with > regexp at all. 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Attachment: [application/x-pkcs7-signature] smime.p7s
« previous php.general (#122650) next »