My 2017 solution is a very lightweight function that gets the current exchange informations from the fixer.io API. It also stores the exchange rate in a daily cookie to prevent further heavy web loading time. You can also choose Sessions for that or remove it:
function convertCurrency($amount, $from = 'EUR', $to = 'USD'){
if (empty($_COOKIE['exchange_rate'])) {
$Cookie = new Cookie($_COOKIE);
$curl = file_get_contents_curl('http://api.fixer.io/latest?symbols='.$from.','.$to.'');
$rate = $curl['rates'][$to];
$Cookie->exchange_rate = $rate;
} else {
$rate = $_COOKIE['exchange_rate'];
}
$output = round($amount * $rate);
return $output;
}
Example usage to convert 100 euro to pounds:
echo convertCurrency(100, 'EUR', 'GBP');