How to Perform Currency Conversions
So,
if you read the first page in this section, you now see the value of being
able to convert from one currency to another. The question that remains is,
how do you do them? I thought you'd never ask!
The first thing you should do is download the currency exchange class. Once you have that, unzip it. Details of usage, limitations, and licensing are included in the .zip file. The quick start instructions for those who just want to jump in are as follows:
- Download currencyexchange.zip
- Unzip the files to a directory within your site
- Include the following code in your PHP page that will display the converted
amount:
<?php
require_once("currencyexchange_class.php");
$cx=new currencyExchange();
$cx->getData();
?> - Where you want the amount conversion to take place, include code similar
to this:
Price $250.00 U.S. dollars
<?php
if ($euro=$cx->Convert("USD","EUR",250)){
$euro=number_format($euro,2);
echo "/ €$euro Euros ";
}
?>
The output from the above should look something like this:
Price $250.00 U.S. dollars / €191.59 Euros
If, for any reason, the exchange rates are not obtained, the above would only show the price in U.S. dollars.
- View the sample file (will open in a new window)
- View the currencyExchange read me file (will open in a new window)
Enjoy!
Gary