> $string = "PHP core developers & Php Programmers."
> $result = "<span style='background:#DDDDDD'>PHP</span> core developers &
> <span style='background:#DDDDDD'>Php</span> Programmers."

$key = "php";
$string = "PHP core developers & Php Programmers.";
$result = preg_replace("#($key)#si", "<span
style='background-color: #dddddd;'>\\1</span>", $string);

                                             Hidayet Dogan
                              [EMAIL PROTECTED]

Pleksus Bilisim Teknolojileri D.T.O. A.S.
----------------------------------------------------------
caldiran sok. 14/6 06420 kolej ankara * www.pleksus.com.tr
tel : +90 312 4355343 * faks: +90 312 4354006

On Mon, 26 Jan 2004, Sheni R. Meledath wrote:

> Hi,
>
> I am looking for a pattern/function which can be used to insert a
> background color for a word in a string.
>
> I want to use this for a keyword search application where the words entered
> are highlighted in the results display. If I do a direct replace the case
> of the text in the string cannot be maintained.
>
> For eg:
> $string = "PHP core developers & Php Programmers."
> $result = "<span style='background:#DDDDDD'>PHP</span> core developers &
> <span style='background:#DDDDDD'>Php</span> Programmers."
>
>
> Sheni R Meledath
> [EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to