note 32924 added to function.ereg-replace
| From: | hillwood at scec dot net dot cn | Date: | Wed, 11 Jun 2003 04:38:57 +0000 |
| Subject: | note 32924 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50148@lists.php.net to get a copy of this message | ||
hi,Damien MARTRAIRE
this is your said:
This is usefull to highlight search words into a search result
<?php
/**
* highlight_search()
*
* @param $search_words array
* @param $string result string
* @param string $bgcolor to highlight search
* @return string with highlight
* @author Damien MARTRAIRE (ATYPIX.COM)
**/
function highlight_search($search_words,$string,$bgcolor='yellow')
{
foreach($search_words as $search_word)
{
$string = eregi_replace("($search_word)",'<span style="background-color:
'.$bgcolor.'">\\1</span>', $string);
}
return $string;
}
print highlight_search(array("foo","bar"),"this texte contain foo, bar and
foobar ans some other words");
?>
it's useful,if keyword include span ,background or color or back , etc, it will appear
errors, have you some way?
print highlight_search(array("foo","color"),"this texte contain foo, bar
and foobar ans some other words");
----
Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32924
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32924&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32924&report=yes