0

Below code was working fine on Production from last few months. Recently it started breaking.

Yesterday it was giving HTTP error issue for file_get_contents function. Today, On Execution it shows Undefined Offset error.

I am not sure what has changed for Finance Google API.

public function getJPYtoUSDExchangeRate(){
        $from    = 'JPY';
        $to    = 'USD';
        $amount  = 1;
        $data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");
        preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
        $converted = preg_replace("/[^0-9.]/", "", $converted[1][0]);
        return number_format(round($converted, 3),2);
}
slavoo
  • 5,798
  • 64
  • 37
  • 39
Pooja
  • 53
  • 1
  • 1
  • 3
  • 1
    Please tag the language. – lebelinoz Mar 20 '18 at 04:01
  • Possible duplicate of [Google finance converter stopped working or changed its url?](https://stackoverflow.com/questions/49324112/google-finance-converter-stopped-working-or-changed-its-url) – Benjamin Smith Mar 21 '18 at 17:04
  • Thank you Benjamin Smith. I tried changing the URL to https://finance.google.com/bctzjpnsun/converter and it's working now. Details are present here: https://stackoverflow.com/questions/49324112/google-finance-converter-stopped-working-or-changed-its-url – Pooja Mar 22 '18 at 01:56
  • Changing URL to finance.google.com/bctzjpnsun/converter was worked few weeks and now again it's breaking from last 2 days. Anything changed again? Is there any better way to get Currency Exchange Rate? – Pooja Jun 05 '18 at 03:08

2 Answers2

1

Finally I found the solution for this with the updated google URL for currency converter https://finance.google.com/bctzjpnsun/converter

Thanks

iamal
  • 159
  • 2
  • 15
0

The problem is with the link, google updated the api link recently, and I found success once on checking 10 times to the existing link. Try changing to this link https://www.google.com/finance/converter

see this https://www.techbuy.in/google-finance-api-currency-converter-not-working-updated-link-check-currency-converter/

iamal
  • 159
  • 2
  • 15
  • Thank you iamal for quick response. Changing to https://www.google.com/finance/converter is not working. I changed it to https://finance.google.com/bctzjpnsun/converter and looks like it's working now. I am not sure what was causing the error. But I will still wait for few days before pushing the changes on Production. Thank you. – Pooja Mar 22 '18 at 01:59