Для получения полного доступа
зарегистрируйтесь.
Snippet,  PHP

Get the currency symbol by currency code from the PHP intl (ICU library)


PHP has excellenet intl extension which is based on ICU library for algorithms and CLDR data for locale data. The code shows how to get currency symbol by currency code using intl.

Example usage:

echo getCurrencySymbol('EUR');
echo getCurrencySymbol('GBP');

would output and £.

By specifying locale code as a second argument you can get currency representation that is common for that locale:

echo getCurrencySymbol('RUR', 'ru_RU');

would output р..

function getCurrencySymbol($currencyCode, $locale = 'en_US')
{
    $formatter = new \NumberFormatter($locale . '@currency=' . $currencyCode, \NumberFormatter::CURRENCY);
    return $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
}

  currency intl icu

Автор


samdark
  • Reputation: 349
  • Snippets : 57
  • Revisions : 5
Подписаться

Чтобы увидеть комментарии, нужно быть участником сообщества

Регистрация