UBB.Dev
Posted By: ekempter string search and replace - 07/24/2005 9:58 PM
The string: I have a Green apple.
I want to search for the word green and highlight it.

My code (where $search_word = green):
$textstring = eregi_replace($search_word, "<b>" . $search_word . "</b>", $textstring);

The result: I have a <b>green</b> apple.

Not bad but how do I retain the original case in $textstring so that the result would be: I have a <b>Green</b> apple.

Changing the $search_word to Green is not an option.

Thank in advance for any assistance.
Posted By: Anno Re: string search and replace - 07/26/2005 1:44 PM
Use string_replace or ereg_replace, and search once for green and once for Green.
Posted By: ekempter Re: string search and replace - 07/31/2005 6:53 AM
The solution:

$description = eregi_replace('(' . $search_word . ')', "<b>\\1</b>", $description);

Thanks for responding Anno.
© UBB.Developers