<?php

class exchange
{
	private $fxRate;
	
	public function __construct($baseCurrency, $Foreigncurrency)
	{
		$url = 'http://download.finance.yahoo.com/d/quotes.csv?s='
			.$baseCurrency .$Foreigncurrency .'=X&f=l1';

		$c = curl_init($url);
		curl_setopt($c, CURLOPT_HEADER, 0);
		curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
		$this->fxRate = doubleval(curl_exec($c));
		curl_close($c);
	}

	public function toBase($amount)
	{
		if($this->fxRate == 0)
			return 0;
			
		return  $amount / $this->fxRate;
	}
	
	public function toForeign($amount)
	{
		if($this->fxRate == 0)
			return 0;
			
		return $amount * $this->fxRate;
	}
};

?>