Re: search highlighting
| From: | Plutarck | Date: | Thu, 12 Apr 2001 12:44:46 +0000 |
| Subject: | Re: search highlighting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48292@lists.php.net to get a copy of this message | ||
You'll probably want to use preg_replace.
For instance:
$string = "/(PHP)/i";
$target = "Please highlight PhP for me.";
echo $target, '<br>';
$target = preg_replace($string, "<b>\\1</b>", $target);
echo $target, '<br>';
\\1 is whatever was found in the first parentheses(sp).
--
Plutarck
Should be working on something...
...but forgot what it was.
""Matt Williams"" <matt@yewlands.com> wrote in message
news:BKEBLPOMMAKCLHIBKBOEAEJIDBAA.matt@yewlands.com...
> Hi
>
> I'm implementing a simple keyword search.
> I want the results to be displayed with the keywords highlighted.
> I am currently using this to highlight the keywords
>
> str_replace($string,"<b>$string</b>",$field);
>
> If I search for php, it will find PHP, PhP etc... but using the above only
> php will will be highlighted, not PHP.
> I've tried eregi_replace but I could only get that to change the case and
> highlight that ie. PHP would become php.
>
> Can anyone point me in the direction of how to highlight the string
> regardless of case but keep the case for the match.
>
> TIA
>
> M@
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>