Location: PHPKode > scripts > lightweight MVC Lang > models/site/lang.php
<?php
class models_sites_lang extends Model{
	private $tags = array(); // this is where we will store the vars for replace
	
	public function __construct(){
		$this->mysql_connection();
		ob_start();
		if(!empty($_COOKIE['lang'])){
			$sql = "SELECT `tag`,`text` FROM `lang` WHERE `lang`='".$_COOKIE['lang']."'";
			$query = mysql_query($sql, $this->connection);
			while($row = mysql_fetch_array($query)){
				$tag = $row['tag'];
				$this->tags[$tag] = $row['text'];
			}
		}else{
			$sql = "SELECT `tag`,`text` FROM `lang` WHERE `lang`='en'";
			$query = mysql_query($sql, $this->connection);
			while($row = mysql_fetch_array($query)){
				$tag = $row['tag'];
				$this->tags[$tag] = $row['text'];
			}
		}
	}
	
	public function setLang($lang){
		setcookie("lang", $lang, time()+2592000);
			$sql = "SELECT `tag`,`text` FROM `lang` WHERE `lang`='".$_COOKIE['lang']."'";
			$query = mysql_query($sql, $this->connection);
			while($row = mysql_fetch_array($query)){
				$tag = $row['tag'];
				$this->tags[$tag] = $row['text'];
			}
	}
	
	public function __get($tag){
		return $this->tags[$tag];
	}
	
	public function __destruct(){
		$content = ob_get_clean();
		preg_match_all('/{%(.*?)%}/', $content, $matches);
		print_r($this->lang);
		foreach($matches[1] as $key => $text){
			$content = str_replace($matches[0][$key], $this->tags[$text], $content);  
		}
		echo $content;
	}
}
?>
Return current item: lightweight MVC Lang