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:

  1. Download currencyexchange.zip
  2. Unzip the files to a directory within your site
  3. 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();
    ?>
  4. 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;$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.

Enjoy!
Gary