php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32219 Alphabetical sort with accented characters
Submitted: 2005-03-07 14:00 UTC Modified: 2005-04-05 11:16 UTC
Votes:2
Avg. Score:2.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: php-france at mattoug dot net Assigned:
Status: Closed Package: *General Issues
PHP Version: 4CVS-2005-03-09 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php-france at mattoug dot net
New email:
PHP Version: OS:

 

 [2005-03-07 14:00 UTC] 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" }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-07 19:31 UTC] sniper@php.net
With what locale do you expect that output?

 [2005-03-07 23:49 UTC] 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-08 23:11 UTC] sniper@php.net
It's a bug if *sort() functions can't handle locales correctly.

 [2005-03-08 23:17 UTC] derick@php.net
No bug here, PHP 4 never had support for sorting locale based. I added this function to PHP 5.0.2 to support it.
 [2005-03-08 23:33 UTC] sniper@php.net
Saying that something is supported in PHP 5 isn't gonna make this 'feature' (or fix, IMO) end up in PHP 4. Backport it is.

 [2005-04-05 10:13 UTC] tony2001@php.net
Derick, so is it a bug or not?
 [2005-04-05 11:16 UTC] derick@php.net
Not a bug, but Jani committed my backported addition to 4.3.12.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 13:01:36 2025 UTC