I found/hacked (and I do mean hacked, I know it's not pretty) the code below.
What I am to accomplish:
- Get both the ask/bid value for 3 currencies
- Currencies are USD, BRL,
- EUR Base currency is ARS
- Avoid getting too fancy, I just need to echo 6 values (bid/ask for each currency from the base currency)
I'm able to get what I think is the average rate, but I'm unsure how to get the bid/ask values.
I do notice that: - if you change $usd_allData[1] to $usd_allData[2], you get the date - if you change $usd_allData[1] to $usd_allData[3], you get the time
If you have any insights or flashes of genius, please send them my way.
Thanks in advance!
<?php
/* USD
------------------------- */
$usd_from = 'USD'; /*change it to your required currencies */
$usd_to = 'ARS';
$usd_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $usd_from . $usd_to .'=X';
$usd_handle = @fopen($usd_url, 'r');
if ($usd_handle) {
$usd_result = fgets($usd_handle, 4096);
fclose($usd_handle);
}
$usd_allData = explode(',',$usd_result); /* Get all the contents to an array */
$usd_Value = $usd_allData[1];
/* EUR
------------------------- */
$eur_from = 'EUR'; /*change it to your required currencies */
$eur_to = 'ARS';
$eur_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $eur_from . $eur_to .'=X';
$eur_handle = @fopen($eur_url, 'r');
if ($eur_handle) {
$eur_result = fgets($eur_handle, 4096);
fclose($eur_handle);
}
$eur_allData = explode(',',$eur_result); /* Get all the contents to an array */
$eur_Value = $eur_allData[1];
/* BRL
------------------------- */
$brl_from = 'BRL'; /*change it to your required currencies */
$brl_to = 'ARS';
$brl_url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $brl_from . $brl_to .'=X';
$brl_handle = @fopen($brl_url, 'r');
if ($brl_handle) {
$brl_result = fgets($brl_handle, 4096);
fclose($brl_handle);
}
$brl_allData = explode(',',$brl_result); /* Get all the contents to an array */
$brl_Value = $brl_allData[1];
echo (
$usd_Value . '<br><hr>' .
$eur_Value . '<br><hr>' .
$brl_Value
)
?>