note 28286 deleted from function.ereg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 29 Aug 2004 12:15:19 +0000 |
| Subject: | note 28286 deleted from function.ereg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75561@lists.php.net to get a copy of this message | ||
Note Submitter: Damien MARTRAIRE
----
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");
?>