Currency Exchange Rates with PHP & XML

So you developed this fantastic business plan. You've started your business and you've got a web site. You're selling your product or service on the web. Everything is going great! All of a sudden, you are doing business all over the world. Your customers are now in different countries, using different currencies. How are they going to know how much something is going to cost them in their currency? Using PHP and its XML parsing capabilities, you can provide prices in many different currencies.

Okay, before we start, let's talk about some boring legal stuff. The reference rates below obtained from the European Central Bank and are based on the regular daily concertation procedure between central banks within and outside the European System of Central Banks, which normally takes place at 2.15 p.m. ECB time (CET).

The below listed currency exchange rates are examples that are updated only once daily (Monday through Friday except holidays) and believed to be correct as of the date indicated. However, as examples, these rates should not be assumed to be entirely accurate and should not be used in financial transactions. The chart below, lists the equivalent amounts that correspond to one United States Dollar.

Select a different base currency:

European Central Bank
Reference rates - May 16, 2012
CurrencyIDRate
Australia DollarAUD1.0059
Brazil ReaiBRL1.9905
Bulgaria LevaBGN1.5354
Canada DollarCAD1.0074
China Yuan RenminbiCNY6.3218
Croatia KunaHRK5.9224
Czech Republic KorunyCZK19.9874
Denmark KronerDKK5.8354
EuroEUR0.7851
Hong Kong DollarHKD7.7688
Hungary ForintHUF231.0567
India RupeeINR54.4952
Indonesia RupiahsIDR9,242.00
Israel New ShekelILS3.8289
Japan YenJPY80.4914
Latvian LatLVL0.5477
Lithuanian LitaLTL2.7106
Malaysia RinggitMYR3.1158
Mexico PesoMXN13.8050
New Zealand DollarNZD1.3033
Norway KronerNOK5.9829
Philippines PesoPHP43.0099
Poland ZlotychPLN3.4150
Romania New LeuRON3.4856
Russia RubleRUB30.8967
Singapore DollarSGD1.2668
South Africa RandZAR8.3106
South Korea WonKRW1,168.16
Sweden KronorSEK7.1416
Switzerland FrancCHF0.9429
Thailand BahtTHB31.4398
Turkey New LiraTRY1.8198
United Kingdom PoundGBP0.6275
United States DollarUSD1.0000

So What?

All right, showing a chart like that is a neat trick, but so what? How does that help you as a web developer? Let's say, for example, you are in the United States and your product sells for $24.95 in U.S. dollars. How much is that in U. K. pounds, or in Euros? Easy! It would be £15.65, or €19.59. Oh, just in case you were curious, it would be 25.13 Canadian dollars, or ¥2,008.26 in Japanese yen.

Note that all the figures in the preceding paragraph are calculated live, based on the above exchange rates! Are you beginning to see the possibilities? Let's say you're in Hong Kong. You sell your product for 200 Hong Kong dollars. What would the price be for someone in the United States? $25.74.

If I have your attention, please read on to see how to perform currency conversions