简体   繁体   English

LC_MONETARY it_IT @ utf8使用PHP在金额前显示欧元符号

[英]LC_MONETARY it_IT@utf8 shows euro symbol before amount with PHP

Setting the locale information as: 将语言环境信息设置为:

$locale = 'it_IT';
$moneyFormat = '%n';

setlocale(LC_MONETARY, $locale.'.utf8');
$optionPrice = money_format($moneyFormat, floatval($option->optionPrice));

The price is shown as: 价格显示为:

€ 23

instead 代替

23 €

I've found the locale identifier p_sign_posn to set the position of the currency symbol but I don't know how to modify it and apparently it's set by default to 1 for the IT locale. 我已经找到了语言环境标识符p_sign_posn来设置货币符号的位置,但是我不知道如何修改它,显然,对于IT语言环境,它默认设置为1。

Anybody could enlightenment me to find a clever solution? 谁能启发我找到一个聪明的解决方案?

Thanks in advance. 提前致谢。

EDIT: The locale for Italy is apparently installed on the system 编辑:意大利的语言环境显然已安装在系统上

vmamp@AMP30:~> locale -a | grep it
it_CH
it_CH.utf8
it_IT
it_IT.utf8
it_IT@euro

To use locale-aware function you have to have the requested locale installed on your computer. 要使用支持区域设置的功能,您必须在计算机上安装请求的区域设置。 If the requested locale is not presented, the call to setlocale fails and nothing is changed. 如果未显示请求的语言环境,则对setlocale的调用将失败,并且不会进行任何更改。

For instance, I have es_ES locale installed, but no it_IT : 例如,我安装了es_ES语言环境,但没有it_IT

setlocale(LC_MONETARY, 'es_ES.utf8');
echo money_format($moneyFormat, floatval(12))
// ⇒ 12,00 €
setlocale(LC_MONETARY, 'en_US.utf8');
echo money_format($moneyFormat, floatval(12))
// ⇒ $12.00
setlocale(LC_MONETARY, 'it_IT.utf8');
echo money_format($moneyFormat, floatval(12))
//   FAIL!!!
// ⇒ $12.00

As you can see, the latter call was ignored ( setlocale returned 0 .) So the problem you encountered is not with a position of eurosign; 如您所见,后面的调用被忽略了( setlocale返回0 )因此,您遇到的问题不是eurosign的位置;而是您的问题。 it's likely a lack of it_IT l10n installed. 可能缺少安装的it_IT l10n。

For italian currency mode you can do: 对于意大利货币模式,您可以执行以下操作:

$money = substr(money_format('%.2n',$number), 4).' $ money = substr(money_format('%。2n',$ number),4)。 €'; €';

given $number = 77500 给定$ number = 77500

you get 你得到

77.500,00 € 77.500,00€

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM