Google is provided free of cost currency converter, In this tutorial we will discuss how 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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";
$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);
}
How to Call function
1
echo convertCurrency('USD','INR',1);