How to get the default currency from the PHP Intl ( ICU library )

前端 未结 1 1987
忘掉有多难
忘掉有多难 2020-12-17 04:31

I use PHP, and like to know how I can get the default currency for a locale via the Internationalization extension (Wrapper for the ICU library)?

Below is a script t

相关标签:
1条回答
  • 2020-12-17 05:28

    Once you set the Locale to the NumberFormatter, you can fetch the Currency Code with

    $formatter = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    
    $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    
    $formatter = new NumberFormatter('ja_JP', NumberFormatter::CURRENCY);
    echo $formatter->getTextAttribute(NumberFormatter::CURRENCY_CODE);
    

    The above would give EUR, USD and JPY.

    0 讨论(0)
提交回复
热议问题