| Conditions | 3 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | public function highlight($string, $needle, $class = 'highlight') |
||
| 22 | { |
||
| 23 | if (null === $needle || '' === $needle) { |
||
| 24 | return $string; |
||
| 25 | } |
||
| 26 | |||
| 27 | $needle = preg_quote($needle, '/'); |
||
| 28 | |||
| 29 | $replacements = [ |
||
| 30 | 'a' => '[áa]', 'e' => '[ée]', 'i' => '[íi]', 'o' => '[óo]', 'u' => '[úu]', |
||
| 31 | 'A' => '[ÁA]', 'E' => '[ÉE]', 'I' => '[ÍI]', 'O' => '[ÓO]', 'U' => '[ÚU]', |
||
| 32 | 'n' => '[ñn]', 'N' => '[ÑN]' |
||
| 33 | ]; |
||
| 34 | |||
| 35 | $needle = str_replace(array_keys($replacements), $replacements, $needle); |
||
| 36 | |||
| 37 | return preg_replace("/(".$needle.")/ui", '<span class="'.htmlentities($class).'">\\1</span>', $string); |
||
| 38 | } |
||
| 39 | } |
||
| 40 |