Currency Conversion using Yahoo Finance API

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 = ''. $From . $To .'=X';
$Handle = @fopen($URL, 'r');

if ($Handle) {
$Result = fgets($Handle, 4096);
$allData = explode(',',$Result);
$Value = $allData[1];

return $Value * $Amount;

$Amount = ConvertCurrency("NZD","USD",25);

2 thoughts on “Currency Conversion using Yahoo Finance API”

  1. Yahoo finance API is not available anymore. I have moved to MarketXLS after this change, much more reliable data.

Leave a Reply

Your email address will not be published. Required fields are marked *