Created
April 9, 2014 10:28
-
-
Save oshanz/10252181 to your computer and use it in GitHub Desktop.
PHP – Google Currency Converter
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 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 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working