Just a quick and dirty PHP function to retrieve information from the Yahoo Finance API to perform a currency conversion
function ConvertCurrency($From,$To,$Amount){
$URL = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $From . $To .'=X';
$Handle = @fopen($URL, 'r');
if ($Handle) {
$Result = fgets($Handle, 4096);
fclose($Handle);
}
$allData = explode(',',$Result);
$Value = $allData[1];
return $Value * $Amount;
}
Usage:
$Amount = ConvertCurrency("NZD","USD",25);
Yahoo finance API is not available anymore. I have moved to MarketXLS after this change, much more reliable data.
Good point, times certainly have changed since 2010. Thanks for the tip!
For those still wanting to do this programatically there are new services such as https://openexchangerates.org