currency converter

Started on the old forum in February 2011 · view the original in the archive · old links redirect here

#converter #currency #function

1 reply · 309 views · started 15 years ago · 1 min read

2 participants
pmbguy Senior · 344 posts #1

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:

 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...

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close