php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36718 sort with SORT_LOCALE_STRING
Submitted: 2006-03-13 15:20 UTC Modified: 2006-03-13 17:19 UTC
From: mpmp at zoznam dot sk Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.2 OS: Linux
Private report: No CVE-ID: None
 [2006-03-13 15:20 UTC] mpmp at zoznam dot sk
Description:
------------
I am using setlocale(LC_ALL, 'slovak');
Accented characters are not properly sorted on Linux. On windows this code runs well. Locales are installed, and other locales related functions run well.

Reproduce code:
---------------
$pole = array (
'čaj',
'ľad',
'ťahaj',
'?bel',
'?la',
'?ver',
'?iť',
'?ger',
'?ler',
'ňano',
'?j',
'Ľadov?');
setlocale (LC_ALL, "slovak");
sort ($pole, SORT_LOCALE_STRING);

Expected result:
----------------
Array ( 
[0] => ?bel 
[1] => ?j 
[2] => čaj 
[3] => ?ger 
[4] => ?ver 
[5] => ľad 
[6] => Ľadov? 
[7] => ňano 
[8] => ?ler 
[9] => ?la 
[10] => ťahaj 
[11] => ?iť )

Actual result:
--------------
Array ( 
[0] => ?bel 
[1] => ťahaj 
[2] => ?j 
[3] => čaj 
[4] => ?ger 
[5] => ?iť 
[6] => ?ver 
[7] => ?la 
[8] => ňano 
[9] => ?ler 
[10] => Ľadov? 
[11] => ľad )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-13 15:25 UTC] derick@php.net
Please send me the example script in a tar.gz archive and I'll have a look.
 [2006-03-13 16:09 UTC] mpmp at zoznam dot sk
sent to your email address.
 [2006-03-13 17:19 UTC] derick@php.net
I received the script and I checked it. There is no bug in PHP, and you can "fix" the issue by:

1. converting your script's encoding to iso-8859-2 (as that is the default encoding on atleast my linux), and not the windows-1250 you use now.
2. Generate locale information with the correct encoding. On my Debian system I do that with:
   a. Edit /etc/locale.gen and add a line that says:
sk_SK  CP1250
   b. Run "locale-gen" (as root)
   c. Then change your script to use "sk_SK" instead of "slovak".

I did solution two and I now get the correct result:
    [0] => ?bel
    [1] => ?j
    [2] => čaj
    [3] => ?ger
    [4] => ?ver
    [5] => ľad
    [6] => Ľadov?
    [7] => ňano
    [8] => ?ler
    [9] => ?la
    [10] => ťahaj
    [11] => ?iť


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 17:01:33 2025 UTC