This api will no longer work as google has closed its iGoogle service from Nov 1, 2013. You may find this alternative method to Convert currency from one format to another.
Hello friends. Here is the google api code to convert the currency from one format to another. You have to pass just three parameteres. i.e. From currency, To currency and the amount to be converted. It will return the converted amount.
function convertCurrency($from,$to,$amount) {
$amount = urlencode($amount);
$from = urlencode($from);
$to = urlencode($to);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from=?$to";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
return round($var,3);
}
Call function
echo convertCurrency('USD','INR',1);
Posting Komentar