直接上代码
function highlight($sString, $aWords) { if (!is_array ($aWords) || emptyempty ($aWords) || !is_string ($sString)) { return false; } $sWords = implode ('|', $aWords); return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString); }