Location: PHPKode > scripts > Czech Course > czech-course/cz_course.php
<?php

/**
 * Class CzechCourse
 *
 * determinate current course of CZK to other courses
 * using XML file provided by czech national bank 
 * such as EUR
 *
 * @license: GPL
 * @author: Michal "Techi" Vrchota
 * @version 1.0 
 * 
 * http://techi.iglu.cz/
 * hide@address.com
 */

/**
 * ReplaceComma
 * 
 * Replace comma in number to dot
 * 
 * @param $number  number to be replaced
 * @return replaced number with dot
 */   
function ReplaceComma($number)
{
	$str = StrVal($number);
	
	$pos = strpos($str, ",");
	
	if($pos !== FALSE)
	{
		$str[$pos] = ".";
	}

	return DoubleVal($str);
}

class CzechCourse
{
	protected $date;
	protected $courses;
	
	public function __construct($date = 0)
	{
		$this->date = $date;
		$this->courses = array();
		
		if(Empty($this->date))
		{
			$this->date = Time();
		}

		// load courses from czech national bank in XML format for selected date
		$xml = simplexml_load_file("http://www.cnb.cz/cz/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml?date=".Date("d.m.Y", $this->date));
		
		$valid_date = $xml["datum"];
		$items = explode(".", $valid_date);
		
		// retrieve date when course was set (because during holidays and weekends are courses not updated)
		$this->date = MKTime(0, 0, 0, $items[1], $items[0], $items[2]);
		
		// store courses
		foreach($xml->tabulka->radek as $item)
		{
			$currency = StrVal($item["kod"]);
			$course = ReplaceComma($item["kurz"]);
			$this->courses[$currency] = $course; 
		}
	}
	
	// get course
	public function getCourse($currency = "EUR")
	{
		return $this->courses[StrToUpper($currency)];
	}
	
	// get all courses
	public function getCourses()
	{
		return $this->courses;
	}
	
	// get course date
	public function getTime()
	{
		return $this->date;
	}
}

?>
Return current item: Czech Course