选择显示字体大小

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


   这个是比较好用的模板,比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(&#36;i=10;&#36;i<=20;&#36;i++)} test {&#36;i} {/loop} 输出(test)20~30的数
{loop:while(&#36;i++<10)} test {&#36;a[&#36;i]} {/loop} 输出(test)20~30的数组

(3),逻辑:{logi:条件语句}其他代码{/logi} 支持if,elseif,else

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

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

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

2,模板输出 :

只输出:eval(cqlctpl(模板文件)) 例子:eval(cqlctpl(&quot;1.tml&quot;))
套模板:{exec:eval(cqlctpl(模板文件))} 例子:{exec:eval(cqlctpl(&#36;templatefile))}
{*这里是在模板中掉用其他模板文件*}

3,函数原代码:

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

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

<h1> {&#36;title} (1.tml) </h1> {*this is a title*}

{loop:for(&#36;i=0;&#36;i<10;&#36;i++)} {*loop start*}

<p> {&#36;body} is {&#36;array[&#36;i]} {*out the msg*}

{logi:if(&#36;i>5)} <p> {&#36;i} is biger than 5 {*logic start*}

{/logi} {*login end*}

{/loop} {*loop end*}

{exec:&#36;time=time()} {*exec start and end*}

{exec:echo &#39;<p>time is &#39;.&#36;time} {*exec start and end*}

{exec:eval(cqlctpl(&#39;2.tml&#39;))} {*this is include other tml*}

模板文件:2.tml的原代码
<p> <h1>this is other tml(2.tml)</h1>
{ exec:test()}

演示的php脚本
tml.php:
<?
function cqlctpl(&#36;file) /*函数作者,cqlc,主页:http://www.cqlc.net,
中文文档案 http://www.cqlc.net/cn_cqlctpl.txt */
{
&#36;fp=fopen(&#36;file,&quot;r&quot;);
&#36;msg=&quot;echo\&quot;&quot;.str_replace(&quot;\&quot;&quot;,&quot;\\\&quot;&quot;,fread(&#36;fp,filesize(&#36;file))).&quot;\&quot;;&quot;;
fclose(&#36;fp);
&#36;oldstr=array(0=>&quot;/\{loop:([^\}]+)\}(.+)\{\/loop\}/si&quot;,
1=>&quot;/\{logi:([^\}]+)\}(.+)\{\/logi\}/si&quot;,
2=>&quot;/\{exec:([^\}]+)\}/si&quot;,
3=>&quot;/(\{\*[^\*]+\*\})/si&quot;
);
&#36;newstr=array(0=>&quot;\&quot;;\\1{echo\&quot;\\2\&quot;;}echo\&quot;&quot;,
1=>&quot;\&quot;;\\1{echo\&quot;\\2\&quot;;}echo\&quot;&quot;,
2=>&quot;\&quot;;\\1;echo\&quot;&quot;,
3=>&quot;&quot;
);
return preg_replace(&#36;oldstr,&#36;newstr,&#36;msg);
}

function test(){echo&quot;<p>这是第二个模板文件哟 ,欢迎你的测试&quot;;} /*定义一个函数*/

&#36;title=&quot;这是第一个模板文件&quot;;

&#36;body=&quot;这里已经开始输出了 &quot;;

for(&#36;i=0;&#36;i<10;&#36;i++)&#36;array[&#36;i]=&quot;hello world &#36;i&quot;;

eval(cqlctpl(&quot;1.tml&quot;));


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)
这是第二个模板文件哟 ,欢迎你的测试


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons