|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-07-25 07:35 UTC] 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 ) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 21:00:01 2025 UTC |
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