test.php:

<?php$title = "测试标题";$a = require 'test.html';$a = exec($a);echo $a;test.html:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title><?php echo $title;?></title></head><body><?php for($i = 0;$i < 10;$i++):?> <p><?php echo $i;?></p><?php endfor;?></body></html>关于smarty模板:

smarty是在类中进行操作的,通过正则把 test.html 中的变量找出来,然后赋值给smarty中的变量,间接的给模板赋值