Skip to content

Instantly share code, notes, and snippets.

@oshanz
Created April 9, 2014 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshanz/10252181 to your computer and use it in GitHub Desktop.
Save oshanz/10252181 to your computer and use it in GitHub Desktop.
PHP – Google Currency Converter
<?php
function currency_convert($from,$to,$amount) {
$string = "1".$from."=?".$to;
$google_url = "http://www.google.com/ig/calculator?hl=en&q=".$string;
$result = file_get_contents($google_url);
$result = explode('"', $result);
$converted_amount = explode(' ', $result[3]);
$conversion = $converted_amount[0];
$conversion = $conversion * $amount;
$conversion = round($conversion, 2);
$rhs_text = ucwords(str_replace($converted_amount[0],"",$result[3]));
$rhs = $conversion.$rhs_text;
$price = preg_replace('_^\D+|\D+$_', "", $rhs);
return number_format($price, 2, '.', ',');
}
echo currency_convert('GBP', 'USD',250.75); # convert 250.75 USD into equivalent GBP
?>
@vedlct
Copy link

vedlct commented Oct 18, 2020

not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment