ok, i was coding an online orders interface that connects to paypal, but for some reason i couldn't send prices in certain currencies without getting an error message... so to work a way around this i modified some code I had to make the following function:
ok, one problem i found is trying to convert bigger numbers, ie: over 100 pounds to ZAR etc doesn't calculate right... wondering if one of the better coders might have any ideas...
PHP Code:
function ZAR_2_USD($amount, $from, $to)
{
$amount = urlencode($amount);
$from_Currency = urlencode($from);
$to_Currency = urlencode($to);
$url = "hl=en&q=$amount$from_Currency%3D%3F$to_Currency";
$rawdata = file_get_contents("http://google.com/ig/calculator?".$url);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
$xchanged = round($var, 2);
return $xchanged;
}
//////////example////////////////
//
//$amount = $_POST['amount']; ie: 28.96
//$from = $_POST['from']; ie: ZAR
//$to = $_POST['to']; ie: USD
// works like: echo "".ZAR_2_USD("28.96", "ZAR", "USD")."";
//or better: echo "".ZAR_2_USD($amount, $from, $to)."";
ok, one problem i found is trying to convert bigger numbers, ie: over 100 pounds to ZAR etc doesn't calculate right... wondering if one of the better coders might have any ideas...
Comment