-
php
Highlight specific words in a phrase
Sometimes, for example, when displaying search results, it is a great idea to highlight specific words. This is exactly what the following function can do:
01:22 Jul 20 2010 | Tags :
function highlight($sString, $aWords) {
if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
return false;
}
$sWords = implode ('|', $aWords);
return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);
}
Owned Code :
Phpsnippets
Add comment
To add a comment, please : Login or Sign up