Skip to content

Instantly share code, notes, and snippets.

View anderson631's full-sized avatar

Anderson Ferreira anderson631

  • Nanpos
  • Caruaru - PE - Brasil
View GitHub Profile
@jwv
jwv / Highlight_Words_In_A_String.php
Created December 18, 2012 14:29
PHP: Highlight Words In A String
<?php
function highlight($astring, $aword) {
if (!is_array ($aword) || !is_string ($astring) || empty ($aword) ) {
return false;
}
$aword = implode ('|', $aword);
return preg_replace ('@\b('.$aword.')\b@si', '<strong style="background-color:red">$1</strong>', $astring);
}