Created
October 15, 2014 19:11
-
-
Save vjandrea/87a659a48562e600f0f7 to your computer and use it in GitHub Desktop.
String highlight preserving case
This file contains 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
<?php | |
// http://www.webdevdoor.com/php/highlight-search-keyword-string-function/#comment-445598 | |
function highlight($haystack, $needle, $color = ‘#F00′) | |
{ | |
return preg_replace("/($needle)/i", sprintf('<span style="color: %s">$1</span>', $color), $haystack); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment