note 32924 deleted from function.ereg-replace by didou

From: Date: Wed, 11 Jun 2003 07:01:09 +0000
Subject: note 32924 deleted from function.ereg-replace by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-50149@lists.php.net to get a copy of this message
Note Submitter: hillwood@scec.net.cn ---- 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");

« previous php.notes (#50149) next »