G'day PHP'ers

I am trying highlight the results from a search, so far I have this working but only 
if the string is an exact match ie: case sensitive, for example:

<?php
$keywords = "foo";
$data = "This is a lower foo. This is an upper FOO. This is a ucase Foo";

$lower = strtolower($keywords);
$upper = strtoupper($keywords);
$ucase = ucwords($keywords);
$words = array($lower, $upper, $ucase);

while ( list($key, $val) = each($words) ) {
$hilite = "<font color=\"#ff0000\">" . $val . "</font>";
$replaced = ereg_replace($val, $hilite, $data);
}

echo $replaced;
?>

Now as metioned this seems to work only for "foo" does anyone have any idea why? 

Also I need to be able to support mutiple keywords ie: foo Foo FOO, so basically I 
know I could split(" ", $keywords) then some how traverse the array making a new array 
of all possible case combinations then in my while loop replace each occurance found 
in $data with the highlighted replacment, sounds easy hmm....

If anyone has any ideas or can see what I am doing wrong so far, it would be mutch 
appreciated.

Regards,

Joseph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to