简单的模板替换
// 模板替换
class demo2 implements ITemplate{
private $varArr=array();
public function setVariable($name,$var){
$this->varArr[$name]=$var;
// var_dump($aa);
// exit;
}
public function getHtml($templat){
foreach (varArr as $name => $value) {
$templat=str_replace("{$name}", $value, $templat);
}
$templat=str_replace("{{$haha}}", $this->varArr, $templat);
return $templat;
}
}
$htmldemo=<<<HTML
<html>
<h1>{{$haha}}</h1>
</html>
HTML;
$demo2=new demo2();
$demo2->setVariable("haha","这是标题");
echo $demo2->getHtml($htmldemo);