Skip to content

Instantly share code, notes, and snippets.

@vjandrea
Created October 15, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjandrea/87a659a48562e600f0f7 to your computer and use it in GitHub Desktop.
Save vjandrea/87a659a48562e600f0f7 to your computer and use it in GitHub Desktop.
String highlight preserving case
<?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