contains(fn (string $term) => str_starts_with($foldedWord, $term)); $html .= $matched ? ''.e($word).'' : e($word); $i = $end; } return new HtmlString($html); } /** * Lower case, without accents; Greek final sigma as σ. */ private static function fold(string $text): string { if (class_exists(Normalizer::class)) { $text = preg_replace('/\p{Mn}+/u', '', Normalizer::normalize($text, Normalizer::FORM_D) ?: $text); } return strtr(mb_strtolower($text), [ 'ά' => 'α', 'έ' => 'ε', 'ή' => 'η', 'ί' => 'ι', 'ό' => 'ο', 'ύ' => 'υ', 'ώ' => 'ω', 'ϊ' => 'ι', 'ϋ' => 'υ', 'ΐ' => 'ι', 'ΰ' => 'υ', 'ς' => 'σ', ]); } private static function isWordChar(string $char): bool { return (bool) preg_match('/[\p{L}\p{N}]/u', $char); } }