|
Posted by Toby Inkster on 03/08/06 10:29
Geoff Coope wrote:
> I have a client that wants a currency converter on their website.
Download this onto your server daily and use it to populate a database:
http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
it contains all the major world currencies' exchange rates against the
Euro. Once the data is in your database, you can use a tiny little bit of
server-side scripting to do conversions. e.g.
<?php
function getExchangeRate ($curr)
{
if ($curr=='EUR') return 1;
// do database stuff here
return $rate;
}
$amount = $_GET['amount'];
$fromcurr = $_GET['fromcurr'];
$tocurr = $_GET['tocurr'];
$euros = $amount / getExchangeRate($fromcurr);
$result = $euros * getExchangeRate($tocurr);
# NOTE: it is not customary to use two decimal places to represent
# *all* currencies, though it is for the majority of currencies.
# NOTE: you may want to make this section smarter to use proper
# currency symbols where available, e.g. $, £, €, ฿, ₨, etc.
printf("<p><b>%.02f %s</b> is approximately <b>%.02f %s</b>.</p>",
$amount, $fromcurr, $result, $tocurr);
?>
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|