PHP Classes
Icontem

File: googlecc.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Brian Formalejo  >  Currency from google  >  googlecc.php  
File: googlecc.php
Role: Class source
Content type: text/plain
Description: Fetches the currency converter query string
Class: Currency from google
Convert money currency using Google search queries
 

Contents

Class file image Download
<?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
    )    
    

*/


?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products