Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function convertCurrency($amount,$from_currency,$to_currency){
- $from_Currency = urlencode($from_currency);
- $to_Currency = urlencode($to_currency);
- $query = "{$from_Currency}_{$to_Currency}";
- $json = file_get_contents("https://free.currencyconverterapi.com/api/v5/convert?q={$query}&compact=ultra");
- $obj = json_decode($json, true);
- $val = floatval($obj["$query"]);
- $total = $val * $amount;
- return number_format($total, 2, '.', '');
- }
- //uncomment to test
- echo convertCurrency(1, 'USD', 'CAD');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement