41 public static function apply($words, $body, $pre =
'<strong>', $post =
'</strong>')
43 if (!is_array($words)) {
44 $words=str_replace(
' ',
' ', $words);
45 $words=explode(
' ', $words);
47 foreach ($words as $word) {
48 $body=Highlighter::splitOnTag($word, $body, $pre, $post);
64 private static function splitOnTag($needle, $haystack, $pre, $post)
66 return preg_replace_callback(
67 '#((?:(?!<[/a-z]).)*)([^>]*>|$)#si',
68 function ($capture) use ($needle, $pre, $post) {
69 $haystack=$capture[1];
70 $p1=mb_stripos($haystack, $needle);
71 $l1=mb_strlen($needle);
74 $ret .= mb_substr($haystack, 0, $p1) . $pre
75 . mb_substr($haystack, $p1, $l1) . $post;
76 $haystack=mb_substr($haystack, $p1+$l1);
77 $p1=mb_stripos($haystack, $needle);
79 $ret.=$haystack.$capture[2];
static apply($words, $body, $pre= '< strong >', $post= '</strong >')
static splitOnTag($needle, $haystack, $pre, $post)