0

I'm having an issue with the localeconv() in PHP. I'm using a Windows PC.

I set my locale to France using setLocale(LC_ALL, 'fra_fra') function. Then I call the localeconv() function to a variable. When I output that variable, below is what I get.


Array
(
    [decimal_point] => ,
    [thousands_sep] => �
    [int_curr_symbol] => EUR
    [currency_symbol] => �
    [mon_decimal_point] => ,
    [mon_thousands_sep] => �
    [positive_sign] => 
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 0
    [p_sep_by_space] => 1
    [n_cs_precedes] => 0
    [n_sep_by_space] => 1
    [p_sign_posn] => 1
    [n_sign_posn] => 1
    [grouping] => Array
        (
            [0] => 3
        )

    [mon_grouping] => Array
        (
            [0] => 3
        )

)

I'm not sure if it is a UTF-8 display issue. I've done the following:

  1. Set my default_charset in PHP.ini to UTF-8
  2. The Content-type on my page is UTF-8
  3. I've also called same in a header i.e. header('Content-type: text/html; charset=utf-8')
  4. I'm using firefox and changed the charset there too, still no luck
  5. I also updated my http.conf file with AddDefaultCharset, but still no cigar

I'm completely stumped and not sure what next to do.

Can anyone help out?

Thanks.

skaffman
  • 398,947
  • 96
  • 818
  • 769
ObiHill
  • 11,448
  • 20
  • 86
  • 135

3 Answers3

2

I think, your output is not UTF-8. Try to use the UTF-8-locale which such be something like fr_fr.UTF-8 or fr_fr.utf8 on most *nix-systems.

By the way: are you sure about the fra_fra-locale? Shouldn't it be fr_fr for french?

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
  • fr_fr doesn't work on Windows machines. This is noted in the documentation for setlocale() here: http://www.php.net/manual/en/function.setlocale.php. fra_fra does work, but the output is what I can't understand, I've set everything I know possible to utf-8. – ObiHill May 14 '10 at 18:40
  • You're on Windows? UTF-8 is a no-go then. Please see my answer here: http://stackoverflow.com/questions/120334/how-to-sort-an-array-of-utf-8-strings/349036#349036 – Stefan Gehrig May 14 '10 at 20:30
  • I'd assume that the output is either Windows-1252, ISO-8859-1 or ISO-8859-15. Perhaps you can use `iconv` or `mb_convert_encoding` o convert it to UTF-8. – Stefan Gehrig May 14 '10 at 20:34
  • I got it to work with the following: iconv('Windows-1252', 'UTF-8', $locale_conv_arr['currency_symbol']) i.e. assuming $locale_conv_arr represents the array as defined in my question. I'm doing a jig right now. Thanks Stefan. – ObiHill May 15 '10 at 20:34
  • This worked for me on Linux. The actual problem is that non-UFT-8 locales weren't installed. I could have installed them, but instead I simple appended ".UTF-8" to whatever locale is selected. – Jabari Jul 11 '15 at 22:32
1

I finally got this to work i.e. to display the proper characters.

Just do the following (please note that this is for Windows):

iconv('Windows-1252', 'UTF-8', $locale_conv_arr['currency_symbol']);

Where $locale_conv_arr represents the array previously defined in my question.

Thanks to Stefan Gehrig for the direction.

Cheers.

ObiHill
  • 11,448
  • 20
  • 86
  • 135
0

There is a PHP extension called "intl" which gives locale information without using operating system functions: it uses UTF-8 exclusively afaics, avoiding this problem.

http://www.php.net/manual/en/book.intl.php

As this was the SO question that came up when I was looking for help on this, I wanted to make sure there was a link...

George Lund
  • 1,269
  • 12
  • 16