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 = "http://www.google.com/ig/calculator?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]);
$converted = $data[0];

return $converted;
}

// Usage

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

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

124Ge29yQQwg8QJvVRwHkVJ3TNLMm5p1er

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

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

Get Live Currency Rate From Yahoo Finance API

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

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

<?php
function yahoofinance_convert($from, $to) {
$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';
$handle = @fopen($url, 'r');

if ($handle) {
$result = fgets($handle, 4096);
fclose($handle);
}
$return = explode(',',$result);
$to_value = $return[1] * 100;

return $to_value;
}

echo "Value of 100 DKK is " . yahoofinance_convert("DKK", "USD") . "$";

?>
No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

12NPGXbHbfoRi689VRG88CF6XaHUM6oj8p

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

VN:F [1.9.22_1171]
Rating: 5.5/6 (4 votes cast)