Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by EselDompteur ( 15 years ago )
<?php
class templateEngine{
  
 private $content;
 private $vars;
 private $tags;
  
 public function __constructor(){
  // Irgendwas...
 }
 
 public function fetch($template){
  $this->content = file_get_contents&#40;"template/".$template.".html"&#41;;
  $this->tags = $this->getTags($this->content);
  $content = $this->parse($this->content);
  $this->content = "";
  $this->vars = "";
  $this->tags = "";
  return $content;
 }
 
 private function getTags($template){
  preg_match_all("/{(.*)}/", $template, $ausgabe);
  $this->tags = array_unique($ausgabe[1]);
  return $this->tags;
 }
 
 public function set($key, $value){
  $this->vars[$key] = $value;
 }
 
 private function parse($content){
//  print_r($this->tags);
  foreach($this->tags AS $value){
   $content = str_replace("{".$value."}", $this->vars[$value], $content);
  }
  $this->content = $content;
  return $this->content;
 }
}
?>

 

Revise this Paste

Your Name: Code Language: