function get_exchange_rate($from, $to) { // eg: AUD to AUD == 1 if ($from == $to) { return 1; } $debug = $_REQUEST["debug"]; usleep(500000); // So we don't hit their servers too hard $debug and print "<br>"; $url = 'http://finance.yahoo.com/d/quotes.csv?f=l1d1t1&s=' . $from . $to . '=X'; $data = file_get_contents($url); $debug and print "<br>Y: " . htmlentities($data); $results = explode(",", $data); $rate = $results[0]; $debug and print "<br>Yahoo says 5 " . $from . " is worth " . $rate * 5 . " " . $to . " at this exchange rate: " . $rate; if (!$rate) { $url = 'http://www.google.com/ig/calculator?hl=en&q=' . urlencode('1' . $from . '=?' . $to); $data = file_get_contents($url); $debug and print "<br>G: " . htmlentities($data); $arr = alloc_json_decode($data); $rate = current(explode(" ", $arr["rhs"])); $debug and print "<br>Google says 5 " . $from . " is worth " . $rate * 5 . " " . $to . " at this exchange rate: " . $rate; } return trim($rate); }
function g($var) { $rtn = $_GET[$var] or $rtn = $_POST[$var] or $rtn = $_REQUEST[$var]; $var == "options" and $rtn = alloc_json_decode($_POST[$var]); return $rtn; }