views:

178

answers:

2

I have an array I'm trying to asort using php. The problem is that the array has accented characters in it and needs to be sorted using "french" rules.

 cote < côte < coté < côté

I've tried many things, like using php collators, but I get the following error :

PHP Fatal error:  Class 'Collator' not found

I've also tried to set locale but it didn't do anything so I'm not sure I was doing it right, or if I need to isntall the locale. I'm a little confused.

I'm using PHP 5.2.4 if that helps. If I use asort without anything, it puts all the words with accented characters at the end.

Thanks.

+1  A: 

The Collator class is part of PHP's internationalization extension, which comes standard with PHP 5.3

Since you have 5.2.4 you'll need to install this extension in order to make use of its classes.

Peter Bailey
Wouldn't it be better to just upgrade to 5.3? Also I'm on ubuntu.
Enkay
If upgrading to 5.3 is a option then I definitely say "go for it". Then you can start using the cool new language features like closures and late static binding.
Peter Bailey
+1  A: 

I ended up installing the French language pack to my server and using the following :

setlocale(LC_COLLATE, 'fr_CA.utf8');
asort($array, SORT_LOCALE_STRING);

Works for my needs...

Enkay