RE: [PHP] Re: Battling with highlighting search criteria
| From: | David Russell | Date: | Mon, 04 Nov 2002 09:10:49 +0000 |
| Subject: | RE: [PHP] Re: Battling with highlighting search criteria | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122643@lists.php.net to get a copy of this message | ||
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.
Anyone who could help??
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 10:42 AM
To: php-general@lists.php.net
Subject: [PHP] Re: Battling with highlighting search criteria
> 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?
How about str_replace?
$result = "This is a test, isn't it?";
$search = "is";
$replacement = '<span class="highlight">' . $search .
'</span>'; $result
= str_replace( $search, $replacement, $result );
HTH
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
Attachment: [application/x-pkcs7-signature] smime.p7s