2

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

I am using the intl extension in php to deal with localizing the content and formatting things. Since I already know the locale such as en_US, is it possible to get the currency of the locale from PHP?

I should get $ or USD if locale is en_US and $ or AUD if locale is en_AU.

I need to get the 3-letter ISO 4217 currency code to pass into numberFormatter::Currency.

Thanks :)

Community
  • 1
  • 1
F21
  • 32,163
  • 26
  • 99
  • 170
  • 1
    I am using numberformatter::Currency from the intl extension to do the formatting, so this approach will not work. – F21 Aug 09 '11 at 03:31
  • 1
    Check out @Gordon 's answer: http://stackoverflow.com/a/8325456/419 – Kev Nov 30 '11 at 11:58

1 Answers1

0

The localeconv() function will give you a number of useful facts about the current locale, including the international currency symbol (as int_curr_symbol).

If the locale you're interested in isn't set as the current locale, you'll have to temporarily switch to it using setlocale().

  • 1
    This would be ideal, but setlocale is so inconsistent across systems that I would rather avoid it. – F21 Aug 09 '11 at 04:30
  • It's about the best you're going to get without hard-coding a table mapping locales to currency symbols, though. Many systems, including Linux, don't have any functions in libc to get data from a locale that isn't active. –  Aug 09 '11 at 04:38
  • If you're using a Framework, or have access to one, you might want to use their implementation which is system agnostic. – Yzmir Ramirez Aug 09 '11 at 06:07