RE: [PHP] Battling with highlighting search criteria

From: Date: Mon, 04 Nov 2002 09:59:20 +0000
Subject: RE: [PHP] Battling with highlighting search criteria
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122649@lists.php.net to get a copy of this message
Ok, this works. 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>. Thanks 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: Justin French [mailto:justin@indent.com.au] Sent: 04 November 2002 12:49 PM To: David Russell Subject: Re: [PHP] Battling with highlighting search criteria Yeap, you need a regexp... $result = eregi_replace($search,"<span class=\"foo\">$search</span>",$result); This will be a little slower that str_replace, but it's the easiest way if you need case insensitivity... Justin on 04/11/02 7:27 PM, David Russell (DavidR@BarloworldOptimus.com) wrote: > Hmmm, old method: > > Find starting point of substring, and do a substr replace (not really > elegant) > > But how can I make your method case insensitive? I presume ereg/preg > replaces. My regexp knowledge is non-existent, however!! > > 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: Justin French [mailto:justin@indent.com.au] > Sent: 04 November 2002 12:27 PM > To: David Russell; php-general@lists.php.net > Subject: Re: [PHP] Battling with highlighting search criteria > > > how are you doing it for only the FIRST??? > > Anyhoo, a simple string replace should do it... I'd do this: > > $result = str_replace($search,"<span > class=\"highlight\">{$search}</span>",$result); > > Justin > > > on 04/11/02 6:27 PM, David Russell (DavidR@BarloworldOptimus.com) > wrote: > >> Hi there, >> >> My brain has just gone very fuzzy... >> >> I have a search string ($search) and a result ($result). I need to >> highlight every occurance of $search in $result. >> >> I know that it means that I need to change (for example) >> >> $result = "This is a test, isn't it?" >> $search = "is" >> >> Into >> >> $result = "th<span class="highlight">is</span> <span >> class="highlight">is</span> a test, <span >> class="highlight">is</span>'nt it" >> >> Now I can easily see how to change the FIRST occurrence of the word, >> but how can I change every occurance? >> >> Thanks >> >> >> >> 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 >> >

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