note 88017 added to function.setlocale

From: Date: Tue, 06 Jan 2009 11:44:19 +0000
Subject: note 88017 added to function.setlocale
Groups: php.notes 
Request: Send a blank email to php-notes+get-148882@lists.php.net to get a copy of this message
For Apache on Windows (wamp), or Linux RedHat (lampp): if you expect the locale from the environment of PHP process instead of defining it by your code, you shall request the value of locale with setlocale and a null value. On windows it is defined in system, not as an env variable, so you cannot see it with getenv(), but the behavior is the same : print with a decimal number with "," if requesting the locale, with "." otherwise. This is different from the red warning above about locale set by another thread. It seems that unless you request the setlocale, the locale conv array is not set with the environment. As a result the formatting of numbers is not following the locale in environment. <?php print getenv("LANG"); print $_ENV['LANG']; print "calling localeconv() directly\n"; print_r(localeconv()); printf("%f",-123.456); print "\ncalling setlocale() before localeconv()\n"; print(setlocale(LC_ALL,null)); print_r(localeconv()); printf("%f",-123.456); ?> calling localeconv() directly Array ( [decimal_point] => . [thousands_sep] => [int_curr_symbol] => [currency_symbol] => [mon_decimal_point] => [mon_thousands_sep] => [positive_sign] => [negative_sign] => [int_frac_digits] => 127 [frac_digits] => 127 [p_cs_precedes] => 127 [p_sep_by_space] => 127 [n_cs_precedes] => 127 [n_sep_by_space] => 127 [p_sign_posn] => 127 [n_sign_posn] => 127 [grouping] => Array ( ) [mon_grouping] => Array ( ) ) -123.456000 calling setlocale() before localeconv() French_France.1252 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 ) ) -123,456000 ---- Server IP: 213.246.51.26 Probable Submitter: 192.54.144.229 ---- Manual Page -- http://www.php.net/manual/en/function.setlocale.php Edit -- https://master.php.net/note/edit/88017 Del: integrated -- https://master.php.net/note/delete/88017/integrated Del: useless -- https://master.php.net/note/delete/88017/useless Del: bad code -- https://master.php.net/note/delete/88017/bad+code Del: spam -- https://master.php.net/note/delete/88017/spam Del: non-english -- https://master.php.net/note/delete/88017/non-english Del: in docs -- https://master.php.net/note/delete/88017/in+docs Del: other reasons-- https://master.php.net/note/delete/88017 Reject -- https://master.php.net/note/reject/88017 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148882) next »