Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
it was working fine, im getting this error since yesterday, i havnt changed the code.

Undefined offset: 1 in /home/u801144134/public_html/tools/function.php on line 21

What I have tried:

function get_currency($from_Currency, $to_Currency, $amount) {
  $amount = urlencode($amount);
  $from_Currency = urlencode($from_Currency);
  $to_Currency = urlencode($to_Currency);

  $url = "http://finance.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency";

  $ch = curl_init();
  $timeout = 0;
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ch, CURLOPT_USERAGENT,
   "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $rawdata = curl_exec($ch);
  curl_close($ch);
  $data = explode('bld>', $rawdata);
  $data = explode($to_Currency, $data[1]);
  return round($data[0], 2);


}
Posted
Updated 23-Mar-18 8:45am
Comments
Richard MacCutchan 22-Mar-18 13:46pm    
Where is line 21?

1 solution

It looks like Google has discontinued that API. The only mention of it I can find is a Google blog post saying it was deprecated in 2012, and a StackOverflow comment from 2016 mentioning that this specific URL no longer works.

A request for https://www.google.com/finance/converter[^] still returns the conversion form. But when you submit the form, or request the URL directly, you are redirected to a generic Google search for "finance".

There are various alternatives listed in this old StackOverflow thread, although quite a few are no longer available:
How do I get currency exchange rates via an API such as Google Finance? - Stack Overflow[^]

For example:
Euro foreign exchange reference rates[^]
https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml[^]

Or:
Currency Conversion Tool For Devs | Free Currency Converter API[^]
 
Share this answer
 
Comments
Member 13741389 28-Mar-18 10:20am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900