Anybody know how to get a currency converter onto your own website?

G

Geoff Coope

Hi all

I have a client that wants a currency converter on their website. I
suggested they just link to an existing one as but was wondering if anybody
knows of a company offering this as something I could embed?

Thanks
Geoff
 
T

Toby Inkster

Geoff said:
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);
?>
 
G

Geoff Coope

Toby thats great too. Thanks very much

Thanks
Geoff



Toby Inkster said:
Geoff said:
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);
?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top