php代码不支持多维数组,注释和没有缓存功能。
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);
&
php代码不支持多维数组,注释和没有缓存功能。的更多相关文章
- php数组倒叙支持多维数组
<?php //一维数组 $test1 = array("a"=>"苹果","b"=>"香蕉",&qu ...
- PHP二维数组如何根据某个字段排序
分享下PHP二维数组如何根据某个字段排序的方法. 从两个不同的表中获取各自的4条数据,然后整合(array_merge)成一个数组,再根据数据的创建时间降序排序取前4条. 本文记录的要实现的功能类似于 ...
- Python代码阅读(第12篇):初始化二维数组
Python 代码阅读合集介绍:为什么不推荐Python初学者直接看项目源码 本篇阅读的代码实现了二维数组的初始化功能,根据给定的宽高初始化二维数组. 本篇阅读的代码片段来自于30-seconds-o ...
- awk的二维数组
awk是不支持二维数组的,它的底层是一维数组,将两个key拼接为一维数组的key. 如下是其初始化和遍历 awk 'BEGIN{ for(i=0;i< 3; ++i) for(j = 0; j ...
- VB.NET 数组的定义 动态使用 多维数组
我们都知道在全部程序设计语言中数组都是一个非常重要的概念,数组的作用是同意程序猿用同一个名称来引用多个变量,因此採用数组索引来区分这些变量.非常多情况下利用数组索引来设置一个循环,这样就能够高效地处理 ...
- python二维数组切片
python中list切片的使用非常简洁.但是list不支持二维数组.仔细研究了一下发现,因为list不是像nampy数组那么规范.list非常灵活.所以没办法进行切片操作. 后来想了两个办法来解决: ...
- shell-变量,字符串,数组,注释,参数传递
Linux的Shell有很多种,常见的有Bourne Shell Bourne Again Shell C Shell K Shell Shell for Root 等,其中Bourne Again ...
- ThinkPHP的cookide保存二维数组的方法
ThinkPHP中的cookie是不支持二维数组的. 如果要保存二维数组.只能特殊处理 $data[263] = array('gid'=>263,'num'=>1); $data[266 ...
- C#的switch与二维数组.....
今天由于工作上的需要, 改了几行C# 的代码, 发现有一些细微的语法区别,与C++, 像switch语句那样, 我一般不会在default后面加上break,语句, 可是发现如果不加上的话,就会报下 ...
随机推荐
- phpcms列表页调用 点击量
很多朋友经常问Phpcms v9的首页.列表页.内容页点击量如何调用.现在就给大家分享phpcms V9如何分别在首页.列表页.内容页调用点击量代码: 1. Phpcms v9首页调用点击量{pc:c ...
- [原]IOS 后台发送邮件
skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git -(void)statrUpLoad:(id) ...
- aspose导出excel文件
using Aspose.Cells; using System; using System.Collections.Generic; using System.Data; using System. ...
- create a cocos2d-x-3.0 project in Xcode
STEP1: Open Terminal SETP2: Run setup.py SETP3: Run source /Users/your_user/.bash_profile( so that e ...
- WAMP运行分析
- Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id)等
对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOOL) isKindOfClass: classObj 判断是否是这个类或者这个类的子类的实例/ 判断是否是这个类 ...
- iptraf:一个实用的TCP/UDP网络监控工具
iptraf是一个基于ncurses的IP局域网监控器,用来生成包括TCP信息.UDP计数.ICMP和OSPF信息.以太网负载信息.节点状态信息.IP校验和错误等等统计数据. 它基于ncurses的用 ...
- 在mysql存储过程中拼接sql解决in的字段类型不匹配问题
一个朋友问我一个问题,他写了一个存储过程,并在存储过程调用了另外一个自定义的函数.该函数返回类型如'1,34,56'的字符串,并将该字符串作为存储过程的select的id条件. begin DECLA ...
- Mac下Intellij IDea发布JavaWeb项目 详解三 (为所有Module配置Tomcat Deployment 并测试web 网页 配置Servlet)
step4 为所有项目配置Deployment 4.1 如图 4.2 [+][Artifact] 4.3 将这里列出的所有内容选中后,点[OK] 4.4 选完是这样,表示,这三个java ee 项目会 ...
- Bootstrap学习总结笔记(24)-- 基于BootstrapValidator的Form表单验证
Form表单进行数据验证是十分必要的,我们可以自己写JS脚本或者使用JQuery Validate 插件来实现.对于Bootstrap而言,利用BootstrapValidator来做Form表单验证 ...