PHP's mb_strtoupper function converts its input string to uppercase. For Turkish characters, "İ" is a special case, the other characters (ŞÇÖĞÜ) work fine with UTF-8 encoding. mb_strtoupper("izmir", 'UTF-8') returns "IZMIR". If you want it to return "İZMİR" you have to have Turkish locale installed on your OS, add setlocale(LC_ALL, 'tr_TR.UTF-8') to your startup index.php and use mb_strtoupper("izmir", 'tr_TR'). If you don't have Turkish locale on your OS, mb_strtoupper("izmir", 'tr_TR') will return false. In your index.php, check if locale is set correctly by issuing echo setlocale(LC_ALL, 0); If the printout is "LC_COLLATE=C;LC_CTYPE=English_United States.1252;..." you were not able to set the locale to Turkish. I have a search function that compares two strings. I don't have Turkish locale on my development environment, therefore I use the following hack (PHP 7.4):
$modProduct = str_replace("İ", "i", $productName); //Change "İ" to "i" so that for UTF-8, it's
uppercase becomes "I" instead of "İ"
$modSearch = str_replace("İ", "i", $searchTerm);
if (strpos(mb_strtoupper($modProduct,'UTF-8'), mb_strtoupper($modSearch, 'UTF-8'))!==false) {...}
No comments:
Post a Comment