1 | <?php |
||
24 | class Highlighter |
||
25 | { |
||
26 | /** |
||
27 | * mbstring encoding |
||
28 | */ |
||
29 | const ENCODING = 'UTF-8'; |
||
30 | |||
31 | /** |
||
32 | * Apply highlight to words in body text |
||
33 | * |
||
34 | * Surround occurrences of words in body with pre in front and post |
||
35 | * behind. Considers only occurrences of words outside of HTML tags. |
||
36 | * |
||
37 | * @param string|string[] $words words to highlight |
||
38 | * @param string $body body of html text to highlight |
||
39 | * @param string $pre string to begin a highlight |
||
40 | * @param string $post string to end a highlight |
||
41 | * |
||
42 | * @return string highlighted body |
||
43 | */ |
||
44 | 1 | public static function apply($words, $body, $pre = '<mark>', $post = '</mark>') |
|
56 | |||
57 | /** |
||
58 | * find needle in between html tags and add highlighting |
||
59 | * |
||
60 | * @param string $needle string to find |
||
61 | * @param string $haystack html text to find needle in |
||
62 | * @param string $pre insert before needle |
||
63 | * @param string $post insert after needle |
||
64 | * |
||
65 | * @return mixed return from preg_replace_callback() |
||
66 | */ |
||
67 | 1 | protected static function splitOnTag($needle, $haystack, $pre, $post) |
|
101 | } |
||
102 |