ID: 38203
Updated by: [EMAIL PROTECTED]
Reported By: thomas at uninet dot se
-Status: Open
+Status: Wont fix
Bug Type: Strings related
Operating System: *
PHP Version: 5.2.6
New Comment:
There's no point in "fixing" this more in PHP_5_2 considering this is
so easily addressed by proper localization tool called "intl".
Here's how:
First: "pecl install intl" (and add the extension to be loaded in your
php.ini of course :)
Then use this script:
<?php
$coll = collator_create( 'sv_SV' );
$arr = array('thomas', 'susanne', 'daniel', 'emelie', 'örjan');
collator_asort( $coll, $arr, Collator::SORT_STRING );
print_r($arr);
?>
Outputs:
Array
(
[2] => daniel
[3] => emelie
[1] => susanne
[0] => thomas
[4] => örjan
)
For more info: http://php.net/intl
Previous Comments:
------------------------------------------------------------------------
[2008-11-02 12:28:48] [EMAIL PROTECTED]
Deassigning since Andrei does not do PHP anymore, it seems.
------------------------------------------------------------------------
[2006-07-26 23:33:49] [EMAIL PROTECTED]
This is Andrei's code, according to the notes in the code.
------------------------------------------------------------------------
[2006-07-25 08:03:40] thomas at uninet dot se
Added support for sv_SE so setlocale returns "sv_SE" but it still
doesn't work.
------------------------------------------------------------------------
[2006-07-25 07:49:54] thomas at uninet dot se
setlocale(LC_ALL, 'se_SV') returns bool(false).
Even if the setlocale doesn't work it still gives a correct response
with strcmp and strcasecmp which (I think) indicates that the *nat*
functions uses another approach than the other compare functions.
------------------------------------------------------------------------
[2006-07-25 07:35:27] thomas at uninet dot se
Description:
------------
The bug http://bugs.php.net/bug.php?id=19795 is still not fixed. When
using swedish characters and sorting them with strnatcmp and
strnatcasecmp the result appears in the wrong order.
Reproduce code:
---------------
<?php
function test1($left, $right) {
return strnatcasecmp($left, $right);
}
function test1b($left, $right) {
return strcasecmp($left, $right);
}
$names = array('thomas', 'susanne', 'daniel', 'emelie', 'örjan');
setlocale(LC_ALL, 'se_SV');
uasort($names, 'test1');
print_r($names);
uasort($names, 'test1b');
print_r($names);
?>
Expected result:
----------------
Array
(
[2] => daniel
[3] => emelie
[1] => susanne
[0] => thomas
[4] => örjan
)
Array
(
[2] => daniel
[3] => emelie
[1] => susanne
[0] => thomas
[4] => örjan
)
Actual result:
--------------
Array
(
[4] => örjan
[2] => daniel
[3] => emelie
[1] => susanne
[0] => thomas
)
Array
(
[2] => daniel
[3] => emelie
[1] => susanne
[0] => thomas
[4] => örjan
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38203&edit=1