Created
May 20, 2012 20:50
-
-
Save apphp-snippets/2759487 to your computer and use it in GitHub Desktop.
You may use this code to highlight specific words in your displaying search results
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 | |
/* Source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address */ | |
function highlight($str, $words){ | |
if(!is_array($words) || empty($words) || !is_string($str)){ | |
return false; | |
} | |
$arr_words = implode('|', $words); | |
return preg_replace( | |
'@\b('.$arr_words.')\b@si', | |
'<strong style="background-color:yellow">$1</strong>', | |
$str | |
); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment