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.

1
  • Try "fr_FR" OR "fr_FR.UTF-8"... Commented Jul 11, 2015 at 22:35

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

5 Comments

fr_fr doesn't work on Windows machines. This is noted in the documentation for setlocale() here: 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.
You're on Windows? UTF-8 is a no-go then. Please see my answer here: stackoverflow.com/questions/120334/…
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.
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.
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.
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.

Comments

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.