I need to highlight single words or phrases matching the $key (whole words, not substrings) in an UTF-8 $text. Such match has to be both case-insensitive and diacritic-insensitive. The highlighted text must remain as it was (including uppercase/lowercase characters and diacritical marks, if present).
The following expression achieved half the goal:
$text = preg_replace( "/\b($key)\b/i", '<div class="highlight">$1</div>', $text );
It's case insensitive and matches whole words but won't highlight the $text portions matching $key if such portions contain diacritical marks not present in $key. E.g. I'd like to have "Björn Källström" highlighted in $text passing $key = "bjorn kallstrom".
Any brilliant idea (using preg_replace or another PHP function) is welcome.