Purchase a VIP membership today for 10$/year only! Click here to read more!

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PHP] Convert currencies using Google and cURL [Snippet]
11-19-2011, 06:01 PM
Post: #1
[PHP] Convert currencies using Google and cURL [Snippet]
Usage
The currency() function take 3 parameters: from, to, and sum. So if you want to convert 100 USD in Euros, here’s what you should do:
echo currency("USD","EUR",100);

Function:
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']);
    $var = $data['0'];
    return round($var,2);
}

Find all posts by this user
Post Reply 




User(s) browsing this thread: 1 Guest(s)