CoderZone.org

Category: >> PHP Code >> Perfect Highlighting Function Bookmark and Share

<< lastnext >>

Snippet Name: Perfect Highlighting Function

Description: This one works very well. :)

Comment: (none)

Author: CoderZone
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;
}
 
?>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 31