7

Why does setlocale(LC_ALL, 'en_GB.UTF8'); return false on Windows Server 2003 R2 - Zend CE PHP 5.3.5 ?

Function in question: setlocale.

hakre
  • 193,403
  • 52
  • 435
  • 836
Marcin
  • 5,469
  • 15
  • 55
  • 69

2 Answers2

11

From the PHP Manual:

The return value of setlocale() depends on the system that PHP is running. It returns exactly what the system setlocale function returns.

So in your case it returns false because the system returns false. It is likely that the locale you're using is not available on your system.

A list of setlocale strings supported by Windows is available here. For British English you want eng, english-uk, or uk. Windows doesn't support multi-byte character sets like UTF-8 though; you will probably end up with Windows-1252.

hakre
  • 193,403
  • 52
  • 435
  • 836
spencercw
  • 3,320
  • 15
  • 20
  • 1
    What exactly are you trying to do? Why do you need to change the system locale? – spencercw Feb 28 '12 at 20:55
  • OK, so for some reason XML files which are UTF-8 encoded processed via XMLReader, XPath fwrite ending up to be not UTF-8 encoded on output, characters getting messed up for some reason, thanks. – Marcin Feb 28 '12 at 21:05
  • 1
    The system locale is almost certainly nothing to do with your issue. Put the code you are having trouble with in your question. – spencercw Feb 28 '12 at 21:07
  • Unfortunetly its to complex - frameworks based but what it do its taking UTF-8 XML on input and write it to other file with not modifiying anything but characters getting messed up anyway. – Marcin Feb 28 '12 at 21:10
  • It's impossible to determine what the problem could be without a small test case that demonstrates the problem, sorry. – spencercw Feb 28 '12 at 21:17
2

I would like to add that the problem of Windows not supporting utf-8 can be improved with something like this:

$str=strftime('%a'); //for example
if(!mb_check_encoding($str,'utf-8')) $str=utf8_encode($str);
Gabriel
  • 2,170
  • 1
  • 17
  • 20