ereg_replace all items in a array
| From: | Joseph H Blythe | Date: | Mon, 29 Jan 2001 15:03:32 +0000 |
| Subject: | ereg_replace all items in a array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-37115@lists.php.net to get a copy of this message | ||
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