Extract Currency Symbol From Currency Code In Yii

Is there a way we can get the currency symbol from the currency code using some inbuilt formatter in Yii ? For eg, I pass ‘USD’ to the function and it returns the dollar symbol ?

I believe this could work:




$locale = CLocale::getInstance('pl_PL');

$symbol = $locale->getCurrencySymbol('USD');



HI Nine,

Thanks for replying.

This does work fine for USD.

However when I try the same for INR - the Indian equivalent, it returns ‘₹’ instead of ‘Rs’ . Where am I going wrong ?

Also I am assuming the pl_PL is a region based parameter. Guessing there would be a global parameter for the same?

Thanks again.

‘pl_PL’ is the locale identifier, use yours.

As for the symbols, it’s in the i18n/data directory in the framework sources, search files there if any of them even contain what you’re looking for. If not, you will have to build your own map from some public data.

I’m looking at something more from this.

I want to do something like this:


<?php echo $currency_symbol.$value ?>

I want that Yii automatically change $currency_symbol from "€" to "$" (for example) in function of the current Locale Id (Language).

Is it possibile?

I tried to do it but the only ways are:

Yii::app()->getNumberFormatter()->formatCurrency(‘100’,‘EUR’);

$locale = CLocale::getInstance($language)->getCurrencySymbol(‘EUR’);

In each situation I’m forced to set “EUR” manually. I don’t want to do it, because if I change the language Yii will not automatically ‘translate’ the symbol.

There is a way to echo just the current currency symbol?

There’s no such data bundled with Yii.

You can use data from the datasets/country-code repo. I created a migration to load it to a database in my demo site.