Return to Snippet

Revision: 55342
at February 3, 2012 05:58 by digitalclubb


Initial Code
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',800.00)

Initial URL

                                

Initial Description
PHP Currency converter function that uses Google

Initial Title
PHP Currency Converter (Google Version)

Initial Tags

                                

Initial Language
PHP