#32219 [Bgs->Ver]: Alphabetical sort with accented characters
| From: | sniper@php.net | Date: | Tue, 08 Mar 2005 22:11:55 +0000 |
| Subject: | #32219 [Bgs->Ver]: Alphabetical sort with accented characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-75128@lists.php.net to get a copy of this message | ||
ID: 32219
Updated by: sniper@php.net
Reported By: php-france at mattoug dot net
-Status: Bogus
+Status: Verified
Bug Type: Arrays related
-Operating System:
+Operating System: *
-PHP Version: 4.3.8
+PHP Version: 4CVS-2005-03-09
New Comment:
It's a bug if *sort() functions can't handle locales correctly.
Previous Comments:
------------------------------------------------------------------------
[2005-03-07 23:49:57] derick@php.net
No bug here, the functions don't understand locales unless you add as
second "sort-flag" parameter SORT_LOCALE_STRING to asort(). This option
is introduced in PHP 5.0.2.
The following works fine (if you have the fr_FR locale installed):
<?php
setlocale(LC_ALL, 'fr_FR');
$table = array("AB" => "Alberta",
"BC" => "Colombie-Britannique",
"MB" => "Manitoba",
"NB" => "Nouveau-Brunswick",
"NL" => "Terre-Neuve-et-Labrador",
"NS" => "Nouvelle-Écosse",
"ON" => "Ontario",
"PE" => "Île-du-Prince-Édouard",
"QC" => "Québec",
"SK" => "Saskatchewan",
"NT" => "Territoires du Nord-Ouest",
"NU" => "Nunavut",
"YT" => "Territoire du Yukon");
asort($table, SORT_LOCALE_STRING);
var_dump($table);
------------------------------------------------------------------------
[2005-03-07 19:31:22] sniper@php.net
With what locale do you expect that output?
------------------------------------------------------------------------
[2005-03-07 14:00:09] php-france at mattoug dot net
Description:
------------
Accented characters are not properly sorted. For example, the right
sorting of "à" is between "a" and "b", for "é" it's
between "e" and
"f", and so on...
Reproduce code:
---------------
$table = array("AB" => "Alberta",
"BC" => "Colombie-Britannique",
"MB" => "Manitoba",
"NB" => "Nouveau-Brunswick",
"NL" => "Terre-Neuve-et-Labrador",
"NS" => "Nouvelle-Écosse",
"ON" => "Ontario",
"PE" => "Île-du-Prince-Édouard",
"QC" => "Québec",
"SK" => "Saskatchewan",
"NT" => "Territoires du Nord-Ouest",
"NU" => "Nunavut",
"YT" => "Territoire du Yukon");
asort($table);
Expected result:
----------------
array(13) { ["AB"]=> string(7) "Alberta" ["BC"]=> string(20)
"Colombie-Britannique" ["PE"]=> string(21)
"Île-du-Prince-Édouard"
["MB"]=> string(8) "Manitoba" ["NB"]=> string(17)
"Nouveau-Brunswick"
["NS"]=> string(15) "Nouvelle-Écosse" ["NU"]=> string(7)
"Nunavut"
["ON"]=> string(7) "Ontario" ["QC"]=> string(6)
"Québec" ["SK"]=>
string(12) "Saskatchewan" ["NL"]=> string(23)
"Terre-Neuve-et-Labrador" ["YT"]=> string(19) "Territoire du
Yukon"
["NT"]=> string(25) "Territoires du Nord-Ouest"}
Actual result:
--------------
array(13) { ["AB"]=> string(7) "Alberta" ["BC"]=> string(20)
"Colombie-Britannique" ["MB"]=> string(8) "Manitoba"
["NB"]=>
string(17) "Nouveau-Brunswick" ["NS"]=> string(15)
"Nouvelle-Écosse"
["NU"]=> string(7) "Nunavut" ["ON"]=> string(7)
"Ontario" ["QC"]=>
string(6) "Québec" ["SK"]=> string(12) "Saskatchewan"
["NL"]=>
string(23) "Terre-Neuve-et-Labrador" ["YT"]=> string(19) "Territoire
du Yukon" ["NT"]=> string(25) "Territoires du Nord-Ouest"
["PE"]=>
string(21) "Île-du-Prince-Édouard" }
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32219&edit=1