问题
I want to display a list of currencies that would have the ISO and the currency symbol in brackets i.e. something like USD($) or GBP(£). The list is supposed to be dynamic, so hard-coding it is out of the question because the user gets to choose what kind of currencies they get to see in the list. I've been able to get the ISO values to show up, but I want the symbols too.
Is there a webservice or some class that can convert 'USD' to '$'?
回答1:
$string_variable = "USD 9.99";
$string_variable = str_replace("USD ", "\$", $string_variable);
echo $string_variable;
will echo $9.99
回答2:
Just to know about currency symbols hitting the webservice each time is not a good idea. It could be possible third party webservice provider can go to server maintenance without informing and in this situation your application will not work.
Its better if you can download the currency symbol against ISO code, create HashMap of it at server start up time and fetch the related value from it.
Below is the link from where you can download the FinalCurrency.xls. https://drive.google.com/file/d/0B5DVIZeIMrCQMGRYT3NFd05CSGM/edit
来源:https://stackoverflow.com/questions/26327699/getting-currency-symbol-from-currency-code