473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

locale and different encoding

R
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

Aug 26 '06 #1
0 1311

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Nuff Said | last post by:
When I type the following code in the interactive python shell, I get 'UTF-8'; but if I put the code into a Python script and run the script - in the same terminal on my Linux box in which I...
22
by: Keith MacDonald | last post by:
Hello, Is there a portable (at least for VC.Net and g++) method to convert text between wchar_t and char, using the standard library? I may have missed something obvious, but the section on...
0
by: Jaime Casanova | last post by:
Hi all, i want to develop a feature in a c program and need some help... the context: a problem that comes over an over with postgresql database is that when you initialize the cluster you...
7
by: Ralf Goertz | last post by:
Hi, since my previous post <455440ad$0$30326$9b4e6d93@newsspool1.arcor-online.netis still unanswered I'd like to rephrase my question. In order to read/write a wstring in UTF-8 encoding it is...
0
by: Michael Goerz | last post by:
Hi, From http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html#guessing-the-encoding: Why should the call locale.setlocale(locale.LC_ALL, '') only be made once? What exactly...
0
by: Thore Harald =?iso-8859-1?Q?H=F8ye?= | last post by:
I have made this testcase: ----------------------- #!/usr/bin/perl #use locale; #use encoding 'iso-8859-1'; use utf8; binmode(STDOUT, ":utf8"); print "\\x{00D8}:\n"; test("\x{00D8}");
24
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
2
by: Giovanni Bajo | last post by:
Hello, I am trying to find a good way to portably get the output of strftime() and put it onto a dialog (I'm using PyQt, but it doesn't really matter). The problem is that I need to decode the...
25
by: Markus Elfring | last post by:
Hello, I have found two class libraries that have got the method "getLanguage". http://www.icu-project.org/apiref/icu4c/classLocale.html#7c0e53c666ea52387d0edae91f75c94f...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.