Reply to locale and different encoding

Your name:

Reply:


Posted by R on 10/31/73 11:57

Hi all,

I have a simple question about locale and PHP5.

I'm using polish characters but I encode them in UTF-8.
I was sorting an array with usort($array, 'strcoll'); but I've entred a
problem.
I was sorting arrays this way:

setlocale(LC_ALL, 'pl_PL.utf8');
usort($array, 'strcoll');

but it turned out to be completely wrong...

I've started to test various encodings on various OS and ended with
this sample PHP script
that sorts UTF-8 encoded array on both Linux and Windows with locale
encoding set to ISO-8859-2:

<? // file encoding is UTF-8
$array = array('Aea', 'Eaz', 'Eaz', 'Eaz', 'Aea', 'Aeas');

var_dump(mb_detect_encoding($array[1])); // shows UTF-8 - OK

// set locale encoding ISO-8859-2
// pl_PL for Linux
// polish_Poland.28592 for Windows
if (PHP_OS == 'WINNT') {
setlocale(LC_ALL, 'polish_Poland.28592');
} else {
setlocale(LC_ALL, 'pl_PL');
}

// sort
usort($array, 'strcoll');

// works OK on both Linux and Windows
var_dump($array);
?>

how come it works on both Linux Gentoo PHP 5.1.1 and
Windows NT PHP 5.1.4?

the contents of $array contents are encoded in UTF-8, but encoding is
set to ISO-8859-2 (via setlocale)

thanks in advance for sheding some light on locale and encoding
R

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация