sdiama
10/28/2016 - 7:47 AM

HIGHLIGHT SPECIFIC WORDS IN A PHRASE

HIGHLIGHT SPECIFIC WORDS IN A PHRASE

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);
}