Home  >  Article  >  php教程  >  cqlctpl php模板开始提供,最好用,功能最强大的模板

cqlctpl php模板开始提供,最好用,功能最强大的模板

WBOY
WBOYOriginal
2016-06-21 09:14:09936browse

模板

这个是比较好用的模板,比Smarty,FastTemplate and PHPLIB Template都好用

中文文档案 http://www.cqlc.net/cn_cqlctpl.txt

这里是演示地址:http://www.cqlc.net/web/tml.php

请尊重作者的劳动成果,下面演示的3个文件下载地址:http://www.cqlc.net/cqlctpl.zip

我的主页是:http://www.cqlc.net

1 标签:

(1),变量:{$key} 可以是一般变量,数组和类的成员,但字符不能用 " ,只能是单引号 '

例子: {$value} ,{$a[0]} ,{$this->a['color']} 这样写是错的{$this->["color"]}

(2),循环:{loop:循环语句}其他代码{/loop} 支持for和while循环

例子: {loop:for($i=10;$i{loop:while($i++
(3),逻辑:{logi:条件语句}其他代码{/logi} 支持if,elseif,else

例子: {logi:if($i==1)} test {$i} {/logi}
{logi:elseif($i==2)} test {$a[$i]} {/logi}
{logi:else} test {$a[$i]} {/logi}

(4),程序:{exec:语句} 程序段,可以是函数,注意字符只能用 ',不能用"
例子 : {exec:$a='hello'.$i} 正确 {exec:$a="hello$i"}错误
{exec:echo $a}
{exec:echo time()}
{exec:$this->outpage(1,2,'index.php')}

(5),{* 模板注释*} 例子:{*这里不会输出的*}

2,模板输出 :

只输出:eval(cqlctpl(模板文件)) 例子:eval(cqlctpl("1.tml"))
套模板:{exec:eval(cqlctpl(模板文件))} 例子:{exec:eval(cqlctpl($Templatefile))}
{*这里是在模板中掉用其他模板文件*}

3,函数原代码:

function cqlctpl($file) /*函数作者,cqlc,主页:http://www.cqlc.net,
中文档案 http://www.cqlc.net/cn_cqlctpl.txt */
{
$fp=fopen($file,"r");
$msg="echo\"".str_replace("\"","\\\"",fread($fp,filesize($file)))."\";";
fclose($fp);
$oldstr=array(0=>"/\{loop:([^\}]+)\}(.+)\{\/loop\}/si",
1=>"/\{logi:([^\}]+)\}(.+)\{\/logi\}/si",
2=>"/\{exec:([^\}]+)\}/si",
3=>"/(\{\*[^\*]+\*\})/si"
);
$newstr=array(0=>"\";\\1{echo\"\\2\";}echo\"",
1=>"\";\\1{echo\"\\2\";}echo\"",
2=>"\";\\1;echo\"",
3=>""
);
return preg_replace($oldstr,$newstr,$msg);
}
4,模板举例:

模板文件:1.tml的原代码

{$title} (1.tml)

{*this is a title*}

{loop:for($i=0;$i

{$body} is {$array[$i]} {*out the msg*}

{logi:if($i>5)}

{$i} is biger than 5 {*logic start*}

{/logi} {*login end*}

{/loop} {*loop end*}

{exec:$time=time()} {*exec start and end*}

{exec:echo '

time is '.$time} {*exec start and end*}

{exec:eval(cqlctpl('2.tml'))} {*this is include other tml*}

模板文件:2.tml的原代码

this is other tml(2.tml)


{ exec:test()}

演示的php脚本
tml.php:

function cqlctpl($file) /*函数作者,cqlc,主页:http://www.cqlc.net,
中文文档案 http://www.cqlc.net/cn_cqlctpl.txt */
{
$fp=fopen($file,"r");
$msg="echo\"".str_replace("\"","\\\"",fread($fp,filesize($file)))."\";";
fclose($fp);
$oldstr=array(0=>"/\{loop:([^\}]+)\}(.+)\{\/loop\}/si",
1=>"/\{logi:([^\}]+)\}(.+)\{\/logi\}/si",
2=>"/\{exec:([^\}]+)\}/si",
3=>"/(\{\*[^\*]+\*\})/si"
);
$newstr=array(0=>"\";\\1{echo\"\\2\";}echo\"",
1=>"\";\\1{echo\"\\2\";}echo\"",
2=>"\";\\1;echo\"",
3=>""
);
return preg_replace($oldstr,$newstr,$msg);
}

function test(){echo"

这是第二个模板文件哟 ,欢迎你的测试";} /*定义一个函数*/

$title="这是第一个模板文件";

$body="这里已经开始输出了 ";

for($i=0;$i
eval(cqlctpl("1.tml"));


5,模板输出结果,见演示:http://www.cqlc.net/web/tml.php


这是第一个模板文件 (1.tml)
这里已经开始输出了 is hello world 0

这里已经开始输出了 is hello world 1

这里已经开始输出了 is hello world 2

这里已经开始输出了 is hello world 3

这里已经开始输出了 is hello world 4

这里已经开始输出了 is hello world 5

这里已经开始输出了 is hello world 6

6 is biger than 5

这里已经开始输出了 is hello world 7

7 is biger than 5

这里已经开始输出了 is hello world 8

8 is biger than 5

这里已经开始输出了 is hello world 9

9 is biger than 5

time is 1059227729


this is other tml(2.tml)
这是第二个模板文件哟 ,欢迎你的测试



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn