note 28286 added to function.ereg-replace
| From: | Damien at rack1 dot php dot net | Date: | Wed, 08 Jan 2003 14:08:04 +0000 |
| Subject: | note 28286 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41825@lists.php.net to get a copy of this message | ||
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");
?>
--
http://www.php.net/manual/en/function.ereg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+28286
http://master.php.net/manage/user-notes.php?action=delete+28286
http://master.php.net/manage/user-notes.php?action=reject+28286