Case issue with eregi_replace in text highlight function

From: Date: Thu, 23 Feb 2006 00:30:51 +0000
Subject: Case issue with eregi_replace in text highlight function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230916@lists.php.net to get a copy of this message
Hi all! I have a text highlight function which does not behave exactly as needed. Behavior is logical but result is cumbersome. Instead of replacing the portion of the text with the same portion of text with some highlighting code added before and after, it replaces the said text with the chunk of text looked for (highlight), which is an issue when there is a difference in case. It is used in a product search engine and it is important to keep the case the same. Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, "<span class=highlight>" . $highlight . "</span>", $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string "macos", the result will be: <span class=highlight>macos</span> X Super Gizmo Not very pritty. How complicated would it be to prevent this from happening? Thanks a lot in advance!

« previous php.general (#230916) next »