# # $$$ is the name of the variable/block # there must be exactly one space between '' # variable and block names must be uppercase class Template{ var $file; //C'tor function Template($file=NULL){ if($file != NULL){ $this->setFile($file); } } //reads the html template file function setFile($file){ $fp = fopen($file,"rb"); $this->file = fread($fp,filesize($file)); fclose($fp); } //sets a predefined strins as template function setString($file){ $this->file = $file; } //replaces a variable by a value function setVar($var,$content){ $pos2 = 0; while($pos1 = strpos($this->file,"{".$var."}",$pos2)){ $pos2 = strpos($this->file,"}",$pos1); $this->file = substr($this->file,0,$pos1).$content.substr($this->file,$pos2+1); $pos2 = $pos1 + strlen($content); } } //replaces a variable with html content function setHtmlVar($var,$html){ $fp = fopen($html,"rb"); $content = fread($fp,filesize($html)); fclose($fp); $this->setVar($var,$content); } //removes a block function removeBlock($block){ $start = strpos($this->file, ""); $end = strpos($this->file, ""); if($start === false || $end === false){ return false; } $end += 18 + strlen($block); $this->file = substr($this->file, 0, $start) . substr($this->file, $end); } //removes all blocks that contain unreplaced variables function removeUnusedBlocks(){ $start = strpos($this->file, "", $start+16)-$start-17); $end = strpos($this->file, ""); if($end === false){ $start = false; } else{ $end += 18 + strlen($blockname); $block = substr($this->file, $start, $end-$start); $var = ereg("\{[A-Z]+\}", $block); if($var !== false){ $this->file = substr($this->file, 0, $start) . substr($this->file, $end); } if($start+1 < strlen($this->file)){ $start = strpos($this->file, "