1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class template {
private $left = '<!--{'; private $right = '}-->';
public function run($str) { return $this->init($str, $this->left, $this->right); }
/** * 模板驱动-默认的驱动 * @param string $str 模板文件数据 * @return string */ private function init($str, $left, $right) { $pattern = array('/'.$left.'/', '/'.$right.'/'); $replacement = array('', ''); return preg_replace($pattern, $replacement, $str); } } $str = "这是一个模板类,简单的模板类,标题为:<!--{Hello World}-->"; $template = new template; echo $template->run($str);
|