Re: Battling with highlighting search criteria
| From: | rija | Date: | Mon, 04 Nov 2002 23:07:16 +0000 |
| Subject: | Re: Battling with highlighting search criteria | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122717@lists.php.net to get a copy of this message | ||
$result = eregi_replace("($search)","<span
class=hightlight>\\0</span>",$result) ;
I use it, and I work fine for me.
----- Original Message -----
From: "David Russell" <DavidR@BarloworldOptimus.com>
To: <php-general@lists.php.net>
Sent: Monday, November 04, 2002 7:27 PM
Subject: [PHP] Battling with highlighting search criteria
> 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
>