Hi,
I like the first solution but there seems to be on BIG problem with it.
I tried to implement it into a payment gateway but I kept on getting a result of 1.
This perplexed me and I eventually found that it is because there is a space used by google for the thousands sparator. Thus the amount of 1 500.00 was returned as one since the rest was exploded. I have created a quick and dirty fix for it.
Let me know if anyone else has experienced this problem.
Here is my solution:
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('"', $rawdata);
$data = explode('.', $data['3']);
$data[0] = str_replace(" ", "",preg_replace('/\D/', '', $data[0]));
if(isset($data[1])){
$data[1] = str_replace(" ", "",preg_replace('/\D/', '', $data[1]));
$var = $data[0].".".$data[1];
} else{
$var = $data[0];
}
return round($var,2); }