we have a basic user search application. one needs to write partial/full user firstname / lastname and the application returns users matching the search. Now we deal with many international users hence have varied character set from varied languages. We wish to improve our search so that even when users replace a language's special character with its english alphabet counterpart it still returns the value. E.g: We should get Müller when we type both 'Mueller' or 'Muller'. I have done this through combination of setlocale and iconv
setlocale(LC_ALL,'de_DE.UTF-8');
$de_stringconv = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$de_wordconv = iconv('UTF-8', 'ASCII//TRANSLIT', $word);
$de_match = strpos(mb_strtolower($de_stringconv), mb_strtolower($de_wordconv)) !== false;
setlocale(LC_ALL, 'en_GB.UTF-8');
$en_stringconv = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$en_wordconv = iconv('UTF-8', 'ASCII//TRANSLIT', $word);
$en_match = strpos(mb_strtolower($en_stringconv), mb_strtolower($en_wordconv)) !== false;
return $en_match || $de_match;
This code ,although effective on german dutch and english names, doesnt not capture turkish ones specially ones that contain "ı" Is there any way to apply a generalised code that deals with all languages' special characters, instead of setting specific setlocale()