Created
April 3, 2012 10:09
-
-
Save tpdn/2290810 to your computer and use it in GitHub Desktop.
簡易テンプレートエンジン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MicroTemplateEngine { | |
public $data = array(); | |
private $tpl; | |
function __construct($f) { | |
$this->tpl = $f; | |
} | |
function __set($name, $value) { | |
$this->data[$name] = $value; | |
} | |
function __toString() { | |
$out = file_get_contents($this->tpl); | |
foreach ($this->data as $_key => $_value) { | |
$out = str_replace('#{' . $_key . '}', $_value, $out); | |
} | |
$out = preg_replace('/#{.*?}/' , '' , $out ); | |
return $out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment