I want to be able to convert from one currency to another, I found a XML API here which covers most of the currencies I use around my site, but the problem I’m experiencing is how to convert from one currency to another with this XML file.
Obviously I parsed and added the currencies and it’s rates to an array like this:
Array
(
[USD] => 1.3412
[JPY] => 107.99
[BGN] => 1.9558
...
The formula to convert from an exchanged rate is this:
$from = 'GBP'; // The currency can be dynamic to a different currency
$to = 'USD'; // this one too
$amount = 400;
$converted_amount = round($amount / $rate, 2);
$rate is what I’m clueless onto what to do – how to convert into the exchange rate that will be able to be dividable to the $amount.
The rates in this XML are actually euro-rates: i.e., EUR/USD, EUR/JPY, etc. So what you need is: