在PHP中获取货币符号 [英] Get currency symbol in PHP
问题描述
NumberFormatter
格式化货币: $ formatter = new NumberFormatter('en_US',NumberFormatter :: CURRENCY);
echo $ formatter-> formatCurrency(123456789,'JPY');
打印:¥123,456,789
>
这是好的,如果你想格式化钱。
但我想要做的是获得货币符号例如¥)给定币种的ISO 4217代码(例如日元)。
我的第一个猜测是尝试使用:
$ formatter-> getSymbol(的NumberFormatter :: CURRENCY_SYMBOL);
但是,在给定的构造函数(en_US)给出locale的货币符号$的情况下。 p>
有没有办法通过货币ISO 4217代码在PHP中获得货币符号?
我使用 https://github.com/symfony/Intl 实现了这一点:
Symfony \Component\Intl\Intl :: getCurrencyBundle() - > getCurrencySymbol('EUR')
返回
' €。
Let's start with simple piece of code to format money with NumberFormatter
:
$formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
echo $formatter->formatCurrency(123456789, 'JPY');
This prints: ¥123,456,789
.
This is ok if you want to format money.
But what I want to do is to get currency symbol (e.g. ¥) for given currency ISO 4217 code (e.g. JPY).
My first guess was to try using:
$formatter->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
But that gives currency symbol for locale given in constructor (en_US), $ in my case.
Is there a way to get currency symbol by currency ISO 4217 code in PHP?
I achieved this using https://github.com/symfony/Intl:
Symfony\Component\Intl\Intl::getCurrencyBundle()->getCurrencySymbol('EUR')
returns
'€'.
这篇关于在PHP中获取货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!