Created
February 3, 2016 14:23
-
-
Save kirilkirkov/390f347759bd56f24061 to your computer and use it in GitHub Desktop.
PHP currency convertor using Google
This file contains 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); | |
} | |
# Call function | |
echo convertCurrency(1, "USD", "INR"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment