Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- - Currency Conversion (currencyconverterapi)
- - Converts one currency to another
- $from - The 3-letter ISO currency to convert from (ie. USD)
- $to - The 3-letter ISO currency to convert to (ie. GBP)
- $amount - The amount of $from to convert to $to (ie. 1000)
- $timeout - Number of seconds to wait before giving up
- */
- public function convertCurrency($from, $to, $amount, $timeout = 5) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://free.currencyconverterapi.com/api/v3/convert?q=" . $from . "_" . $to . "&compact=y");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $data = curl_exec($ch);
- curl_close($ch);
- $arr = json_decode($data, true);
- return $arr[$from . "_" . $to]["val"] * $amount;
- }
Advertisement
Add Comment
Please, Sign In to add comment