Kobus Beets .co.za
PHP: How to get currency value from Yahoo
Here is a php function that can be used to get current currency values from Yahoo.
<?php function get_currency_value($from, $to) {
$url = "http://finance.yahoo.com/d/quotes.csv?f=l1&s=$from$to=X";
$handle = fopen($url, 'r');
if ($handle) {
$result = fgetcsv($handle);
fclose($handle);
$rate = $result[0];
return $rate;
}
}
echo 'R'.get_currency_value('USD', 'ZAR'); ?>
The method, as I used it, will return 1 USD in ZAR.
Here is the results on the date of testing: R7.8791
This function may be useful for someone out there.
Archives






