RE: [PHP] Re: Battling with highlighting search criteria
| From: | David Russell | Date: | Mon, 04 Nov 2002 11:49:02 +0000 |
| Subject: | RE: [PHP] Re: Battling with highlighting search criteria | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122658@lists.php.net to get a copy of this message | ||
Hi Erwin,
Great thanx, my brain is cleared <grin>. Well, a little more...
Where would I be able to find more info about regexp's?
TIA
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 12:08 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Re: Battling with highlighting search criteria
> 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>.
Read my reply to your previous reply ;-))
But...some more explanation:
$result = preg_replace( '/(' . $search . ')/i', "<span
class=\"highlight\">\$1</span>", $result );
The first argument is the pattern, which is '/(for)/i' in the case of
searching for "for". That will match every occurence of "for", "For",
"fOr", and so on. The case insensitivy is reached by the "i" modifier at
the end of the pattern. The second argument is the replace string. The
$1 is an backward reference to the first item between brackets. That'll
mean that the from the word Forward, the $1 parameter will contain
"For". So, the "For" -part from "Forward" will be replaced with
<span
class="highlight">For</span> and that's exactly what you want
(right?)...
Hope this clears your brain up ;-)))
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
Attachment: [application/x-pkcs7-signature] smime.p7s