I am improving our video search page page to highlight search terms in the results. As the user can enter judas priest, but the video has judas priest, in this text I have to use regular expressions to keep the source text.
My code works, but I have problems with special type characters Å”, Ä and ž, it seems that it Preg_Replace()will only match if the case is the same (despite the modifier /ui). My code is:
$Content = Preg_Replace ( '/\b(' . $term . '?)\b/iu', '<span class="HighlightTerm">$1</span>', $Content );
I also tried this:
$Content = Mb_Eregi_Replace ( '\b(' . $term . '?)\b', '<span class="HighlightTerm">\\1</span>', $Content );
But it also does not work. It will match "SREÄA" if the search query is "SREÄA", but if the search query is "sreÄa", it will not match it (and vice versa).
So how do I do this job?
update: I set the locale and internal encoding:
Mb_Internal_Encoding ( 'UTF-8' );
$loc = "UTF-8";
putenv("LANG=$loc");
$loc = setlocale(LC_ALL, $loc);
source
share