PHP – Google Currency Converter
As you may know, Google has a calculator feature built in their search engine, which can be used to convert measures, currencies, get stock quotes, weather data and many other features
Here is a simple php function that converts a currency into another using the Google calculator API .
This example uses cURL , so you have to have it enabled for this code to work .
Example Code :
- <?php
- function currency($from_Currency,$to_Currency,$amount) {
- $amount = urlencode($amount);
- $from_Currency = urlencode($from_Currency);
- $to_Currency = urlencode($to_Currency);
- $url = “http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$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(‘”’, $rawdata);
- $data = explode(‘ ‘, $data[‘3′]);
- $var = $data[‘0′];
- return round($var,3);
- }
- ?>
Hope it will be useful for you!
Follow @phpzag

Thanks for the good writeup. It in truth used to be a enjoyment account it. Look advanced to more introduced agreeable from you! However, how can we be in contact?