Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
Created November 14, 2015 22:28
Show Gist options
  • Save d1i1m1o1n/edf0605aabeaaa5ef7f9 to your computer and use it in GitHub Desktop.
Save d1i1m1o1n/edf0605aabeaaa5ef7f9 to your computer and use it in GitHub Desktop.
PHP highlight words in text
foreach (explode(' ', $_REQUEST["q"]) as $key => $value) {
$arItem["NAME"] = preg_replace('/'.$value.'/iu', '<span class="search-term">\\0</span>', $arItem["NAME"]);
$arItem["PREVIEW_TEXT"] = preg_replace('/'.$value.'/iu', '<span class="search-term">\\0</span>', $arItem["PREVIEW_TEXT"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment