cqlctpl php模板開始提供,最好用,功能最強大的模板
Jun 21, 2016 am 09:14 AM模板
這個是比較好用的模板,比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} 可以是一般變量,數(shù)組和類的成員,但字符不能用 " ,只能是單引號 '
例子: {$value} ,{$a[0]} ,{$this->a['color']} 這樣寫是錯的{$this->["color"]}
(2),循環(huán):{loop:循環(huán)語句}其他代碼{/loop} 支持for和while循環(huán)
例子: {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:語句} 程序段,可以是函數(shù),注意字符只能用 ',不能用"
例子 : {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,函數(shù)原代碼:
function cqlctpl($file) /*函數(shù)作者,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) /*函數(shù)作者,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"
這是第二個模板文件喲 ,歡迎你的測試";} /*定義一個函數(shù)*/
$title="這是第一個模板文件";
$body="這里已經(jīng)開始輸出了 ";
for($i=0;$i
eval(cqlctpl("1.tml"));
5,模板輸出結(jié)果,見演示:http://www.cqlc.net/web/tml.php
這是第一個模板文件 (1.tml)
這里已經(jīng)開始輸出了 is hello world 0
這里已經(jīng)開始輸出了 is hello world 1
這里已經(jīng)開始輸出了 is hello world 2
這里已經(jīng)開始輸出了 is hello world 3
這里已經(jīng)開始輸出了 is hello world 4
這里已經(jīng)開始輸出了 is hello world 5
這里已經(jīng)開始輸出了 is hello world 6
6 is biger than 5
這里已經(jīng)開始輸出了 is hello world 7
7 is biger than 5
這里已經(jīng)開始輸出了 is hello world 8
8 is biger than 5
這里已經(jīng)開始輸出了 is hello world 9
9 is biger than 5
time is 1059227729
this is other tml(2.tml)
這是第二個模板文件喲 ,歡迎你的測試

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to the problem that php exec cannot be executed: 1. Find the php configuration file php.ini, search for "disable_functions" in the file, and remove "exec" and "shell_exec"; 2. Go to the server to modify the file permissions; 3. Modify the configuration The safe mode is "safe_mode=On".

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

In today's era of rapid technological development, programming languages ??are springing up like mushrooms after a rain. One of the languages ??that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

With the rapid development of Internet technology, Web applications have become an indispensable part of people's lives and work. How to build and deploy web applications more efficiently has also become a hot topic. This article will introduce how to use Golang's web framework Echo framework and Docker to build an efficient web application. 1. About the Echo Framework The Echo Framework is a high-performance web framework written in Golang. It is characterized by being lightweight, simple, easy to use and efficient. ByEch

php提交表單通過后,彈出的對話框怎樣在當前頁彈出php提交表單通過后,彈出的對話框怎樣在當前頁彈出而不是在空白頁彈出?想實現(xiàn)這樣的效果:而不是空白頁彈出:------解決方案--------------------如果你的驗證用PHP在后端,那么就用Ajax;僅供參考:HTML code
