Convert Currency using Google finance calculator with PHP

Google_Finance_Beta_logo
Convert currency from one country to another easily with Google’s finance calculator, using that it’s possible to collect the output using PHP.

Please check below URL:

https://www.google.com/finance/converter

Use below code to extract actual curreny from html:

function convertCurrency($amount, $from, $to){
$data = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from&to=$to");
preg_match("'<span class=bld>(.*?)</span>'si",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3),2);
}

echo convertCurrency("1.00", "USD", "INR");
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s