JTemplate.class.php
001
002
/**
003
* @author Jiawei
004
* @Completed in 2012-6-29 0:23
005
*/
006
class JTemplate{
007
//通过assign函数传入的变量临时存放数组
008
private $templateVar = array();
009
//模板目录
010
private $templateDir = '';
011
//编译目录
012
private $templateCompileDir = '';
013
014
private $fileName = '';
015
/**
016
* 构造函数
017
* @param string $templateDir 模板目录
018
* @param string $templateComplieDir 模板编译目录
019
*/
020
public function __construct($templateDir,$templateComplieDir){
021
$this->templateDir = $templateDir;
022
$this->templateCompileDir = $templateComplieDir;
023
}
024
/**
025
* 显示模板
026
* @param string $fileName 模板文件名
027
*/
028
public function display($fileName){
029
$this->fileName = $fileName;
030
if(file_exists($this->templateDir.'/'.$this->fileName)){
031
$compileFileName = $this->templateCompileDir.'/'.$this->file_safe_name().'.php';
032
if(!file_exists($compileFileName) || filemtime($compileFileName)templateDir.'/'.$this->fileName)){
033
$this->del_old_file();
034
$this->compile();
035
}
036
extract($this->templateVar);
037
include $compileFileName;
038
}else{
039
$this->error('Sorry,the template file '.$this->fileName.' does not exist!!');
040
}
041
}
042
/**
043
* 获取编译文件名
044
*/
045
private function get_compile_file(){
046
$compileFile = explode('.',$this->fileName);
047
unset($compileFile[count($compileFile)-1]);
048
return implode('.',$compileFile);
049
}
050
/**
051
* 编译
052
*/
053
private function compile(){
054
$fileHandle = @fopen($this->templateDir.'/'.$this->fileName, 'r');
055
while(!feof($fileHandle)){
056
$fileContent = fread($fileHandle,1024);
057
}
058
fclose($fileHandle);
059
$fileContent = $this->template_replace($fileContent);
060
//$compileFile = $this->get_compile_file($fileName);
061
$fileHandle = @fopen($this->templateCompileDir.'/'.$this->file_safe_name().'.php','w');
062
if($fileHandle){
063
fwrite($fileHandle, $fileContent);
064
fclose($fileHandle);
065
}else{
066
$this->error('Sorry,Compile dir can not write!');
067
}
068
}
069
/**
070
* 模板传值
071
* @param string $valueName 模板中使用的变量名
072
* @param $value 变量值
073
*/
074
public function assign($valueName,$value){
075
$this->templateVar[$valueName] = $value;
076
}
077
078
/**
079
* 模板正则替换
080
* @param string $content 替换内容
081
* @return string 替换过后的内容
082
*/
083
private function template_replace($content){
084
$orginArray = array(
085
'//s',
086
'//s',
087
'/(.+?)/s',
088
'//s',
089
'//s',
090
'//s',
091
'//s',
092
'//s',
093
'/\{P:(.+?)\:}/s',
094
'/\{C:(\w+)\}/s',
095
'/\{I:(.+?)\}/s',
096
'/\{F:(.+?)\}/s',
097
'/\{EF:(.+?)\}/s',
098
'/\{([a-zA-Z0-9_\[\]\'\"\$\.\x7f-\xff]+)\}/s',
099
);
100
101
$changeArray = array(
102
'',
103
'$$3){$countLoop++;?>',
104
'$1',
105
'',
106
'',
107
'',
108
'',
109
'',
110
'',
111
'',
112
'templateDir.'/$1";?>',
113
'',
114
'',
115
'',
116
);
117
return $repContent=preg_replace($orginArray,$changeArray,$content);
118
}
119
/**
120
* 删除旧文件
121
*/
122
private function del_old_file(){
123
$compileFile = $this->get_compile_file($this->fileName);
124
$files = glob($this->templateCompileDir.'/'.$compileFile.'*.php');
125
// print_r($files);
126
if($files){
127
@unlink($files[0]);
128
}
129
}
130
/**
131
* 编译文件名安全处理方法
132
* @return string 返回编译文件名
133
*/
134
private function file_safe_name(){
135
$compileFile = $this->get_compile_file($this->fileName);
136
return $compileFile.filemtime($this->templateDir.'/'.$this->fileName);
137
}
138
139
/**
140
* 错误输出函数
141
* @param string $content 错误输出信息
142
*/
143
private function error($content){
144
$stringHtml = '
145
$stringHtml .= 'Error information:
';
146
$stringHtml .= '';
147
$stringHtml .= $content;
148
$stringHtml .= '';
149
$stringHtml .= '
150
exit($stringHtml);
151
}
152
}
153
?>
index.php
view sourceprint?
01
02
/**
03
* @author Jiawei
04
*/
05
include_once 'JTemplate/JTemplate.class.php';
06
$template = new JTemplate('template','compile');
07
$a = array('a','b','c','d');
08
define('_CORE_','aaa');
09
$template->assign('a', $a);
10
$template->display('index.html');
11
?>
作者:袁家伟

技嘉的主板怎么设置键盘开机首先,要支持键盘开机,一定是PS2键盘!!设置步骤如下:第一步:开机按Del或者F2进入bios,到bios的Advanced(高级)模式普通主板默认进入主板的EZ(简易)模式,需要按F7切换到高级模式,ROG系列主板默认进入bios的高级模式(我们用简体中文来示范)第二步:选择到——【高级】——【高级电源管理(APM)】第三步:找到选项【由PS2键盘唤醒】第四步:这个选项默认是Disabled(关闭)的,下拉之后可以看到三种不同的设置选择,分别是按【空格键】开机、按组

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

主板上SPDIFOUT连接线序最近我遇到了一个问题,就是关于电线的接线顺序。我上网查了一下,有些资料说1、2、4对应的是out、+5V、接地;而另一些资料则说1、2、4对应的是out、接地、+5V。最好的办法是查看你的主板说明书,如果找不到说明书,你可以使用万用表进行测量。首先找到接地,然后就可以确定其他的接线顺序了。主板vdg怎么接线连接主板的VDG接线时,您需要将VGA连接线的一端插入显示器的VGA接口,另一端插入电脑的显卡VGA接口。请注意,不要将其插入主板的VGA接口。完成连接后,您可以

广联达软件是一家专注于建筑信息化领域的软件公司,其产品被广泛应用于建筑设计、施工、运营等各个环节。由于广联达软件功能复杂、数据量大,对电脑的配置要求较高。本文将从多个方面详细阐述广联达软件的电脑配置推荐,以帮助读者选择适合的电脑配置处理器广联达软件在进行建筑设计、模拟等操作时,需要进行大量的数据计算和处理,因此对处理器的要求较高。推荐选择多核心、高主频的处理器,如英特尔i7系列或AMDRyzen系列。这些处理器具有较强的计算能力和多线程处理能力,能够更好地满足广联达软件的需求。内存内存是影响计算

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver CS6
视觉化网页开发工具

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。