php代码:
simplet.class.php
<?php
class SimpleT {
private $t_vars;
private $templates_dir;
private $templates_c_dir;
private $cache;
private $cache_dir;

public function __construct() {
$this->templates_dir = ./templates/;
$this->templates_c_dir = ./templates_c/;
$this->cache = 0;
$this->cache_dir = ./cache/;
}
public function setDir($dir, $type = template) {
if(is_dir($dir)) {
if($type == template)
$this->templates_dir = rtrim($dir, /)./;
elseif($type == template_c)
$this->templates_c_dir = rtrim($dir, /)./;
elseif($type == cache)
$this->cache_dir = rtrim($dir, /)./;
else
return false;
return true;
} else {
return false;
}
}

public function cache($time) {
if(is_numeric($time)) {
$this->cache = $time;
return true;
} else {
return false;
}
}

public function assign($var, $value = NULL) {
if (is_array($var)) {
foreach ($var as $key => $val) {
$this->t_vars[$key] = $val;
}
} else {
$this->t_vars[$var] = $value;
}
}
private function comp($filename) {
try {
if(!$fp = fopen($filename, r)) {
throw new Exception(Can not open . $filename);
}
$filesize = filesize($filename);
if($filesize <= 0) {
throw new Exception(The file size must > 0 );
}
$content = fread($fp, $filesize);
fclose($fp);
unset($fp);

$content = preg_replace("/<%=([$a-zA-Z0-9_]{1,})%>/","<?php echo \$$1 ;?>", $content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,}).loop%>/", "<?php foreach(\$$1 as \$$1_key => \$$1_val) { ?>",$content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,}).loop(([$a-zA-Z0-9_]{1,}))%>/", "<?php foreach(\$$1 as \$$2) { ?>", $content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,}).loop(([$a-zA-Z0-9_]{1,}),([$a-zA-Z0-9_2881064151]{1,}))%>/", "<?php foreach(\$$1 as \$$2 => \$$3) { ?>", $content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,}).key%>/", "<?php echo \$$1_key ;?>", $content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,}).value%>/", "<?php echo \$$1_val ;?>", $content);
$content = preg_replace("/<%([$a-zA-Z0-9_]{1,})\?%>/", "<?php if(\$$1 == true) { ?>", $content);
$content = preg_replace("/<%end%>/","<?php } ?>", $content);
$content = preg_replace("/<%##common##%>([^<%##end##%>]{0,})<%##end##%>/", "<?php /* $1 */ ?>", $content);
if (preg_match_all("/<%{([^(}%>)]{1,})}%>/", $content, $files)) {
$this->comp($this->templates_dir . $files[1][0]);
}
$content = preg_replace("/<%{([^(}%>)]{1,})}%>/", "<?php include {$this->templates_c_dir}simplet_comp_$1.php; ?>", $content);
echo $content;
$fp = fopen($this->templates_c_dir . simplet_comp_ . basename($filename) . .php, w);
if(!fwrite($fp, $content)) {
throw new Exception(Can not write content in the . $filename);
&

最新文章

  1. 深入揭秘HTTPS安全问题&amp;连接建立全过程
  2. B2B多商铺初期权限数据库设计
  3. php基础31:正则匹配-元字符
  4. 其他窗体赋值给comboBox实现值的回显,并使赋的值处于选中状态(根据text获取selectedindex)
  5. 使用val()另一个妙用------选中select/checkbox/radio的值
  6. sort merge join导致temp被爆菊
  7. URAL 1018 (金典树形DP)
  8. Python协程的引入与原理分析
  9. cocos creator入门
  10. 在经过身份验证的服务中不支持跨域 javascript 回调
  11. TCP/IP协议---UDP协议
  12. 文本编辑框QTextEdit
  13. 前端框架VUE----箭头函数
  14. 【题解】Luogu UVA12345 Dynamic len(set(a[L:R]))
  15. linux开启远程访问端口
  16. USACO 铂金 T1
  17. 实习第一周第一天:接口 extends是继承类,implement是实现接口,原接口里面的方法填充,方法名也是不变,重写override是父类的方法名不变,把方法体给改了
  18. iOS 下 Podfile 使用方法
  19. GUI程序设计3
  20. springMVC框架介绍以及运行流程(图解)

热门文章

  1. Linux的wget命令
  2. kettle教程一
  3. Vim 操作符命令和动作命令
  4. java.util.concurrent.RejectedExecutionException 线程池饱和
  5. Linux命令之乐--iconv
  6. [置顶] 深入探析Java线程锁机制
  7. C语言的f(open)函数(文件操作/读写)
  8. Java网络编程之查找Internet地址
  9. Xcode - 添加自定义代码提示
  10. Swift - 可选类型详解