Created
February 2, 2016 10:34
-
-
Save sedera-tax/c817323982212e582467 to your computer and use it in GitHub Desktop.
Currency converter api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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).' '.$to; | |
} | |
echo convertCurrency(1000, "USD", "MGA"); | |
echo '<br />'; | |
echo convertCurrency(1000, "EUR", "MGA"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment