Advertisement
Guest User

bob

a guest
Jun 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function convertCurrency($amount,$from_currency,$to_currency){
  2.  
  3. $from_Currency = urlencode($from_currency);
  4. $to_Currency = urlencode($to_currency);
  5. $query = "{$from_Currency}_{$to_Currency}";
  6.  
  7. $json = file_get_contents("https://free.currencyconverterapi.com/api/v5/convert?q={$query}&compact=ultra");
  8. $obj = json_decode($json, true);
  9.  
  10. $val = floatval($obj["$query"]);
  11.  
  12. $total = $val * $amount;
  13. return number_format($total, 2, '.', '');
  14. }
  15.  
  16. //uncomment to test
  17. echo convertCurrency(1, 'USD', 'CAD');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement