0

I am using Google Currency Convertor API and I don't know for some reasons its showing me all values 0. It sometimes works but mostly it shows 0 as value, can't sort out whether Google's API is down or something wrong in my code.

$final_rateUSD = // Current USD value + our commission
$rateWithcommsellvalue = // Current USD value + our commission
$final_rateAUD = get_currency('USD', 'AUD', $final_rateUSD);
$final_rateSellAUD = get_currency('USD', 'AUD', $rateWithcommsellvalue);

function get_currency($from_Currency, $to_Currency, $rate) {
    $amount = urlencode($rate);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
    $get = explode("<span class=bld>", $get);
    $get = explode("</span>", $get[1]);
    $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
    return round($converted_amount, 5); 
}
Karthik Malla
  • 5,570
  • 12
  • 46
  • 89
  • 2
    screen scrapping does not an api make, there are real currency api's –  Jul 03 '14 at 21:59
  • http://stackoverflow.com/questions/3139879/how-do-i-get-currency-exchange-rates-via-an-api-such-as-google-finance –  Jul 03 '14 at 22:00
  • Why not use a __real__ [exchange rate API](http://rate-exchange.appspot.com/currency?from=USD&to=AUD) – Mark Baker Jul 03 '14 at 22:02
  • @MarkBaker - I never used it but when I tried to open it for the first time it reverted OVER QUOTA. – Karthik Malla Jul 03 '14 at 22:05

0 Answers0