Last active
June 19, 2016 12:56
-
-
Save M-O-Z-G/c945d5ec8b4f9ac4bc34abc1b5a08cbe to your computer and use it in GitHub Desktop.
PHP currency converter with 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 converterCurrency($price) { | |
$price = (float) $price; | |
if ( $country == 'ru') { //Your switching rule here | |
$cur_glyph = ' ₽'; // Currency Glyph | |
$amount = urlencode($price); | |
$from_Currency = urlencode('USD'); //Initial Currency | |
$to_Currency = urlencode('RUB'); //Target Currency | |
$get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency"); | |
$get = explode("<span class=bld>", $get); | |
$get = explode("</span>", $get[1]); | |
$converted_amount = round((string) preg_replace("/[^0-9\.]/", null, $get[0]), 2); | |
$result = $converted_amount . $cur_glyph; //Output | |
} else { | |
$cur_glyph = '$'; | |
$result = $cur_glyph . $price; //Default Output | |
} | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment