You are here: Re: Anybody know how to get a currency converter onto your own website? « HTML « IT news, forums, messages
Re: Anybody know how to get a currency converter onto your own website?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация