#28527 [Bgs]: Sorting arrays in utf-8 charset not possible

From: Date: Wed, 26 May 2004 15:04:13 +0000
Subject: #28527 [Bgs]: Sorting arrays in utf-8 charset not possible
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-60010@lists.php.net to get a copy of this message
ID: 28527 User updated by: marek at lewczuk dot com Reported By: marek at lewczuk dot com Status: Bogus Bug Type: Arrays related Operating System: Windows XP PHP Version: 5CVS-2004-05-26 (dev) New Comment: Ok, so lets try to do it with usort() and strcoll(). Strcoll() isn't working at all - it always return 2147483647. So Previous Comments: ------------------------------------------------------------------------ [2004-05-26 14:21:20] derick@php.net PHP sorts according to ascii, not a charset so this is not a bug. You will need to use usort() and strcoll() to get this to work. Not a bug -> bogus. ------------------------------------------------------------------------ [2004-05-26 14:06:13] marek at lewczuk dot com Description: ------------ One year ago I have send info about a bug related on sorting arrays with special, language specific characters like ¶±æ. The bug has "closed" status, so it should be working. But is not... All characters are encoded in UTF-8 and also I have made proper setLocale. I don't know if this is a problem with Windows or PHP, but I think that this bug will be also present on Linux machines. The code: SetLocale(LC_COLLATE, $GLOBALS['__OS__'] == "WINDOWS" ? "Polish_Poland.65001" : "pl_PL.UTF-8"); SetLocale(LC_CTYPE, $GLOBALS['__OS__'] == "WINDOWS" ? "Polish_Poland.65001" : "pl_PL.UTF-8"); $array = array ("¦liwka", "Zook", "Alfa", "Beta", "Shit"); sort($array); print_r($array); Current result of sorting: Array ( [0] => Alfa [1] => Beta [2] => Shit [3] => Zook [4] => ¦liwka ) And it should be: Array ( [0] => Alfa [1] => Beta [2] => Shit [3] => ¦liwka [4] => Zook ) Reproduce code: --------------- SetLocale(LC_COLLATE, $GLOBALS['__OS__'] == "WINDOWS" ? "Polish_Poland.65001" : "pl_PL.UTF-8"); SetLocale(LC_CTYPE, $GLOBALS['__OS__'] == "WINDOWS" ? "Polish_Poland.65001" : "pl_PL.UTF-8"); $array = array ("¦liwka", "Zook", "Alfa", "Beta", "Shit"); sort($array); print_r($array); Expected result: ---------------- Array ( [0] => Alfa [1] => Beta [2] => Shit [3] => ¦liwka [4] => Zook ) Actual result: -------------- Array ( [0] => Alfa [1] => Beta [2] => Shit [3] => Zook [4] => ¦liwka ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28527&edit=1

« previous php.bugs (#60010) next »