我有这个简单的代码:
<?php
setlocale('LC_MONETARY', 'fr_CA.UTF-8');
echo money_format('%+#10n', '-4562.75834');
print_r(localeconv());
?>
谁通常应该给-4 562,76 $.但结果总是如此:
(4 562,76 $)
localeconv()的输出:
Array
(
[decimal_point] => .
[thousands_sep] =>
[int_curr_symbol] => CAD
[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] => 0
[grouping] => Array
(
)
[mon_grouping] => Array
(
[0] => 3
[1] => 3
)
)
我们可以看到负号应该是 – 但不是()
安装了服务器上的语言环境(Debian 7):
# locale-gen
Generating locales (this might take a while)...
en_CA.UTF-8... done
fr_CA.ISO-8859-1... done
fr_CA.UTF-8... done
Generation complete.
我尝试过PHP 5.4.45和5.6.17
最佳答案 您已将LC_MONETARY放在单引号之间.
它需要作为一个const变量存在,它被设置为不在引号中.
setlocale(LC_MONETARY, 'fr_CA.UTF-8');