[英]Php get current locale for LC_MONETARY
I'm using this code to display an amount in the current locale. 我正在使用此代码显示当前区域设置中的金额。
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%i', $number);
My question is, how can I see the current value for LC_MONETARY ? 我的问题是,如何查看LC_MONETARY的当前值? If I do a simple echo the value seems the same and I can't find any getlocale function.
如果我做一个简单的回声,值看起来是一样的,我找不到任何getlocale函数。
echo LC_MONETARY;
setlocale(LC_MONETARY, 'it_IT');
echo LC_MONETARY;
Update : LC_MONETARY is the category of function affected so it makes sense the value is the same. 更新:LC_MONETARY是受影响的功能类别,因此值是相同的。 But how can I see the current locale info then ?
但是,如何查看当前的区域设置信息呢?
$oldLocale = setlocale(LC_MONETARY, 'it_IT');
// setlocale() will return the old value if the locale could
// be set (return value greatly depends on the system's underlying
// setlocale() implementation)
$oldLocale = setlocale(LC_MONETARY, '0');
// using '0' as the locale-argument will result in the current setting
//being returned without affecting the locale setting itself
See the note for the $locale
parameter in the setlocale()
documentation. 请参阅
setlocale()
文档中$locale
参数的注释。
The value of the constant LC_MONETARY
will never change. 常量
LC_MONETARY
的值永远不会改变。 When setting a locale with setlocale(LC_MONETARY, ...)
, you're not changing the LC_MONETARY
constant, you're setting the locale for the "monetary" category . 使用
setlocale(LC_MONETARY, ...)
设置区域设置时,您没有更改LC_MONETARY
常量,而是设置“货币”类别的区域设置。 This locale setting happens in the background and is not visible outwardly. 此区域设置在后台进行,并且在外部不可见。 The
LC_MONETARY
constant is just an identifier for the category. LC_MONETARY
常量只是该类别的标识符。
Usually you don't need to know what's currently set. 通常您不需要知道当前设置的内容。 You should simply set your desired locale when needed.
您只需在需要时设置所需的区域设置即可。
Have a look at the localeconv()
function ( http://www.php.net/manual/en/function.localeconv.php ): 看看
localeconv()
函数( http://www.php.net/manual/en/function.localeconv.php ):
print_r(localeconv());
Outputs (depending on what you set with setlocale()
): 输出(取决于您使用
setlocale()
设置的内容):
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] => 1
[p_sep_by_space] => 1
[n_cs_precedes] => 1
[n_sep_by_space] => 1
[p_sign_posn] => 1
[n_sign_posn] => 2
[grouping] => Array
(
)
[mon_grouping] => Array
(
[0] => 3
[1] => 3
)
)
The main thing you'll probably care about is the int_curr_symbol
result. 您可能关心的主要事情是
int_curr_symbol
结果。
$data = localeconv();
$symbol = $data['int_curr_symbol'];
switch($symbol){
case 'EUR':
// Euro
break;
case 'USD':
// US Dollars
break;
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.