PHP – Google Currency Converter

The given PHP example is a currency converter, and can convert one currency amount into other
currency amount.

Code Example:
<?php 
function currency_convert($from,$to,$amount) {
	$string = "1".$from."=?".$to;
	$google_url = "http://www.google.com/ig/calculator?hl=en&q=".$string;
	$result = file_get_contents($google_url);
	$result = explode('"', $result);
	$converted_amount = explode(' ', $result[3]);
	$conversion = $converted_amount[0];
	$conversion = $conversion * $amount;
	$conversion = round($conversion, 2);
	$rhs_text = ucwords(str_replace($converted_amount[0],"",$result[3]));
	$rhs = $conversion.$rhs_text;
	$price = preg_replace('_^\D+|\D+$_', "", $rhs);
	return number_format($price, 2, '.', ',');
}
echo currency_convert('GBP', 'USD',250.75); # convert 250.75 USD into equivalent GBP
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

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