Skip to content

Instantly share code, notes, and snippets.

@ashumeow
Forked from dcblogdev/gist:8067095
Last active January 9, 2018 13:23
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 ashumeow/9e7445ef858db40885d8ae2c0830a043 to your computer and use it in GitHub Desktop.
Save ashumeow/9e7445ef858db40885d8ae2c0830a043 to your computer and use it in GitHub Desktop.
Use Google finance calculator to convert currency with php
<?php
function convertCurrency($amount, $from, $to){
$data = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from&to=$to");
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3),2);
}
echo convertCurrency("10.00", "AED", "USD");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment