David Ninan
David Ninan

Reputation: 47

Google finance Currency converter not working

My Code for currecy converter using google finance is not working

$amount="10";
      $from="USD";
      $to="INR";
    $data = file_get_contents("https://finance.google.com/bctzjpnsun/converter?a=$amount&from=$from&to=$to");
    preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
    $converted = preg_replace("/[^0-9.]/", "", $converted[1]);
    echo number_format(round($converted, 3),2); exit;

I am getting the result as 0.00.

Is there any alternative method other than this?

Upvotes: 1

Views: 704

Answers (2)

PaulRM
PaulRM

Reputation: 409

The URL of google are not working anymore

Upvotes: 1

annz
annz

Reputation: 319

$amount="10";
$from="USD";
$to="INR";
$url = file_get_contents('https://free.currencyconverterapi.com/api/v5/convert?q=' . $from . '_' . $to . '&compact=ultra');
$json = json_decode($url, true);
$rate = implode(" ",$json);
$total = $rate * $amount;
$rounded = round($total); 
return $rounded;

use this code

Upvotes: 4

Related Questions