Last active
May 19, 2020 10:07
-
-
Save sdiama/dea8263d443e12442028177e06702630 to your computer and use it in GitHub Desktop.
HighLight Specific Words in a Phrase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment