PHP – Google Currency Converter

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

Code Example:
function currency_convert($from,$to,$amount) {
	$string = "1".$from."=?".$to;
	$google_url = "".$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


  1. avatarкровельные материалы

    Your means of describing everything in this article is in fact pleasant, every one
    can simply know it, Thanks a lot.

  2. avatarRqrWM

Leave a Comment

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