php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9671 Sorting arrays with norwegian letters
Submitted: 2001-03-10 07:51 UTC Modified: 2001-03-10 13:36 UTC
From: webmaster at sandnessjoen dot net Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.4pl1 OS: RedHar 7.0
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: webmaster at sandnessjoen dot net
New email:
PHP Version: OS:

 

 [2001-03-10 07:51 UTC] webmaster at sandnessjoen dot net
I think I have found a bug in the function 'sort'. It does not sort correct with norwegian letters. The norwegian alphabeth is made of 29 letters. The three last ones are spesial for norway (and sweden and denmark). 

Heres a sample of our alphabeth:
abcdefghijklmnopqrstuvwxyz???

And here are some code...

<?

// List of norwegian names, with norwegian letters
$to_be_sorted = array(mamma, ?yvind, sondre, v?rner, ?rlend, odd, hedvig, ?smund, birgit);

sort($to_be_sorted);

for ($i = 0; $i < sizeof($to_be_sorted); $i ++) {
  echo $to_be_sorted[$i]."<br>\n";
}

?>

This prodused this putput:

birgit 
hedvig 
mamma  
odd 
sondre 
v?rner 
?smund 
?rlend 
?yvind 

But it should have been:

birgit
hedvig
mamma 
odd 
sondre 
v?rner 
?rlend 
?yvind 
?smund 

Yours H?kon Flat?y

PS: PHP is GREAT!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-10 13:36 UTC] sniper@php.net
The sort() function isn't locale aware. Use this instead:

<?

// List of norwegian names, with norwegian letters
$to_be_sorted = array(mamma, ?yvind, sondre, v?rner, ?rlend, odd, hedvig, ?smund, birgit);

setlocale("LC_COLLATE", "no_NO");
usort($to_be_sorted, "strcoll");

print_r($to_be_sorted);

?>

http://www.php.net/strcoll
http://www.php.net/setlocale

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC