php+icu+库是什么意思,如何从PHP Intl(ICU库)中的货币代码获取货币符号
不幸的是,這并不像應(yīng)該的那樣容易,但是這里是如何通過貨幣代碼獲取貨幣符號,用于區(qū)域設(shè)置:
function getCurrencySymbol($locale, $currency)
{
// Create a NumberFormatter
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
// Prevent any extra spaces, etc. in formatted currency
$formatter->setPattern('¤');
// Prevent significant digits (e.g. cents) in formatted currency
$formatter->setAttribute(NumberFormatter::MAX_SIGNIFICANT_DIGITS, 0);
// Get the formatted price for '0'
$formattedPrice = $formatter->formatCurrency(0, $currency);
// Strip out the zero digit to get the currency symbol
$zero = $formatter->getSymbol(NumberFormatter::ZERO_DIGIT_SYMBOL);
$currencySymbol = str_replace($zero, '', $formattedPrice);
return $currencySymbol;
}
使用區(qū)域設(shè)置進(jìn)行測試:ar,cs,da,de,en,en_GB,en_US,es,fr,fr_CA,he,it,ja,ko,nb,nl,ru,sk,sv,zh
貨幣測試:澳元,巴西雷亞爾,加元,人民幣,歐元,英鎊,港元,英鎊,英鎊,日元,韓元,墨西哥比索,紐元,泰銖,新臺幣,美元,越南盾,XAF,XCD,XOF,XPF
總結(jié)
以上是生活随笔為你收集整理的php+icu+库是什么意思,如何从PHP Intl(ICU库)中的货币代码获取货币符号的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: phpstudy php日志,phpst
- 下一篇: php 获取企业号用户,微信企业号 获取