Snippet Name: Perfect Highlighting Function
Description: This one works very well. :)
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009
|
<?PHP
// highlight words in a string
FUNCTION highlight($text, $search) {
$text = PREG_REPLACE( "/(^|\s|,!|;)(".PREG_QUOTE($search, "/").")(\s|,|!|&|$)/i", "\\1<span class='hlstyle'>\\2</span>\\3", $text );
RETURN $text;
}
?> |