Get Live Currency Conversion From Google Finance API

Here is a simple PHP Function to get live currency conversion from Google Finance API

In my example i am gettting the value of 100 US Dollar in Euro

function google_finance_convert($from_Currency, $to_Currency, $amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);

$url = "$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);

$data = explode('"', $rawdata);
$data = explode(' ', $data[3]);
$converted = $data[0];

return $converted;

// Usage

echo google_finance_convert("USD", "EUR", "100"); // echos how much 100$ is in Euro

VN:F [1.9.22_1171]
Rating: 0.0/6 (0 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *