Page 1 of 1

Highlighting search words

Posted: Thu Feb 13, 2003 12:19 pm
by leebo
Hi

I am wanting to highlight the words that the user searches for:

<?php
if(!isset($searchItem)) { $searchItem = "Orange"; }
function callback($buffer) {

global $searchItem;
// surround search item items with highlight class
return (ereg_replace($searchItem, "<span class='highlight'>$searchItem</span>", $buffer));

}

ob_start("callback");

?>

<html>
<style>
.highlight {
background: #44AA44;
color: white;
}
</style>
<body>
<p>It's like comparing bannanas to oranges to apples to peaches.
</body>
</html>


This works fine how ever if the user seached Orange instead of orange ( uppercase for the first letter ) then it does not work.
Does anyone know how to make it so it highlights the word either case

Thanks

Posted: Thu Feb 13, 2003 12:26 pm
by daven
eregi_replace() -- case insensitive replacement.

Posted: Thu Feb 13, 2003 12:32 pm
by leebo
Great Stuff it works

As easy as adding one char :D

I was looking for the answer for over 1 hour but could not find it !

Thanks a lot