/ Published in: JavaScript
Expand |
Embed | Plain Text
// Author: Piotr Filipek // Site: www.dealis.pl // Version: 1.9.2 class Template { private $toChange; private $str; public function Template($AFileName){ $this->str = file_get_contents($AFileName); } public function set($AKey, $AValue=''){ if(is_array($AKey)){ foreach($AKey as $BValue => $BKey){ echo $BValue." => ".$BKey."<br />"; $CKey = '{'.$BValue.'}'; $this->toChange[$CKey] = $BKey; } } else { $AKey = '{'.$AKey.'}'; $this->toChange[$AKey] = $AValue; } } public function display(){ if (count($this->toChange)>0){ $tmpKeys = array_keys($this->toChange); foreach($tmpKeys as $currentKey){ $this->str = str_replace($currentKey, $this->toChange[$currentKey], $this->str); } } echo $this->str; } } // SIMPLE CODE - FIRST include 'includes/class.template.php'; $tpl = new Template("themes/default/szablon.html"); $tpl->set("SITE:TITLE", "Simple title"); $tpl->set("SITE:COPY", "My footer"); $tpl->display(); // SIMPLE CODE - SECOND include 'includes/class.template.php'; $tpl = new Template("themes/default/szablon.html"); $tpl->set( array( "SITE:TITLE" => "Simple title", "SITE:COPY" => "My footer" ) ); $tpl->display();
You need to login to post a comment.
