Skip to content

Instantly share code, notes, and snippets.

@rohankhudedev
Last active February 25, 2017 20:19
Show Gist options
  • Save rohankhudedev/d5ea7b53408bca65d6a78879c15f586c to your computer and use it in GitHub Desktop.
Save rohankhudedev/d5ea7b53408bca65d6a78879c15f586c to your computer and use it in GitHub Desktop.
currency converter google finance calculator can be for all language - php
//I have used google finance calculator for this purpose
function convertCurrency($amount, $from, $to){
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
$data = file_get_contents($url);
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return round($converted, 3);
}
//# Call function
echo convertCurrency(1, "USD", "INR");
//More info can be found here
//http://www.altafweb.com/2013/11/convert-currency-using-google-finance.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment