Current cost in your local currency
Archive - Originally posted on "The Horse's Mouth" - 2004-09-16 07:11:46 - Graham EllisIf you're selling internationally on line, it's a nice gesture to your customers to tell them roughly what things cost in their local currency, before you charge their credit card in pounds, dollars, euros, or whatever currency you use yourself. Tables of current exchange rates are easy enough to find, but they change all the time and your site can rapidly become misleading.
The European Central Bank provides a daily set of conversion rates to and from the Euro on their web site, and those are mid-rates so that you can easily convert from (say) pounds to Euros, then on to Rand, fairly accurately. The data is available as an XML feed, and can be very easily picked up in a PHP web page:
$stuff = file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
We have a sample PHP script in operation on our web site
PHP's ability to read data from a URL as easily as it can read data from a file has a very wide range of other uses too, but you need to take care of issues such as copyright, robot exclusion and the traffic you'll generate before you write such pages. In the case of the ECB page, the page is stated to be publicly available information, and live scripts that are heavily used should be written to cache a copy of the data locally from your script as it only changes once every 24 hours.