I'm working on a simple search engine for a newspaper application. When the user types a keyword, a results page is shown, highlighting the term with a color.
I'm currently doing this:
$title = str_ireplace($term, "<span class='highlight'>$term</span>", $note->Title);
Great, str_ireplace()
makes the case-insensitive search, but when the case doesn't match the note (i.e. the user looks for "MONEY" and the note says "money"), this happens:
malvinas | Resultados de la búsqueda 1. malvinas: Argentina va a la ONU y Londres se enfurece » en Actualidad [...] Naciones Unidas, Ban-Ki Moon, ante quien reiterará que se cumplan las resoluciones de la ONU sobre el tema de la soberanía de las Islas [...]
The original title of the note is "Malvinas: Argentina va a la ONU y Londres se enfurece" (not "malvinas: ", etc.)
How can I do a highlight without changing the original word's CaSe?