Location: PHPKode > scripts > Currency from google > currency-from-google/googlecc.php
<?php

/*
	Google currency converter	
*/

class CC{

	// The url to fetch search results, do not change #{money}# #{moneyfrom}# #{moneyto}#
	var $url = 'http://www.google.com.ph/search?q=#{money}#+#{moneyfrom}#+to+#{moneyto}#';
	
	function Convert( $denomination, $fromCurrency , $toCurrency ){
		$finalurl = str_replace( array('#{money}#','#{moneyfrom}#','#{moneyto}#'), array( $denomination, $fromCurrency, $toCurrency),$this->url );
		
		# Renders the google page result
		$htmlrender = file_get_contents( $finalurl );		
		preg_match_all('/\<h2 class\=r\>\<font size\=\+1\>\<b\>([0-9.]+[^a-zA-Z]+[0-9.]+)[^a-zA-Z]+([a-zA-Z\ ]+) = ([0-9.]+[^a-zA-Z]+[0-9.]+)[^a-zA-Z]+([a-zA-Z\ ]+)\<\/b\>\<\/h2\>/i',$htmlrender,$matches);
		
		# Returns an array of results array(from_amount, from_currency, to_amount , to_currency)
		return (!empty($matches[4][0])) ? array('from_amount'=>$matches[1][0],'from_currency'=>$matches[2][0],'to_amount'=>$matches[3][0],'to_currency'=>$matches[4][0]) : false;

	}

}

/*

	Example usage
*/
	$cc = new CC();
	$result = $cc->Convert(3000, 'MXN', 'USD');
	print_r($result);
/*
	This will return an array:
	Array
	(
		[from_amount] => 3000
		[from_currency] => Singapore dollars
		[to_amount] => 96 591.6846
		[to_currency] => Philippine pesos
	)	
	

*/


?>
Return current item: Currency from google