


powerpoint template silently and simply wrote a template engine
Engine file
Copy code The code is as follows:
/**
* An OOP template engine developed by Momo based on Discuz template engine, which can support template caching and generate hash md5 values.由hash值来判断模板是否被修改,假如被修改则重新生成缓存文件,假如没有被修改,则直接调用缓存文件.
* 版本:1.0.0.1 beta 测试版
*/
class mmtp{
var $left_tags="{";
var $right_tags="}";
var $tp_suffix=".html";
var $cache_suffix=".tpl";
var $tp_dir="./";
var $cache_dir="./";
/**
* 允许循环嵌套的次数,默认为5
*
* @var unknown_type
*/
var $nest = 5;
/**
* 模板路径
*
* @param unknown_type $tp_dir
* @return mmtp
*/
function __setdir($tp_dir){
if(file_exists($tp_dir)){
$this->tp_dir=$tp_dir;
}else{
$this->error("模板路径不存在");
}
}
/**
* 设置缓存目录
*
* @param unknown_type $cache_dir
*/
function __setcdir($cache_dir){
if(file_exists($cache_dir)){
$this->cache_dir=$cache_dir;
}else{
$this->error("缓存路径不存在");
}
}
/**
* 输出错误信息
*
* @param unknown_type $msg
*/
function error($msg){
print "
}
/**
*/
function tp($file){
$tp_path=$this->tp_dir.$file.$this->tp_suffix;
$fp=fopen($tp_path,"rb");
if(!$this->file_test($tp_path,"r") && !$this->match_hash($file)){
$template=$this->file_read($tp_path);
$var_regexp = "((\$[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)([[a-zA-Z0-9_-."'[]$x7f-xff]+])*)";
$const_regexp = "([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)";
$template = preg_replace("/([nr]+)t+/s", "\1", $template);
$template = preg_replace("//s", "{\1}", $template);
$template = preg_replace("/{langs+(.+?)}/ies", "languagevar('\1')", $template);
$template = str_replace("{LF}", "="\n"?>", $template);
$template = preg_replace("/{(\$[a-zA-Z0-9_[]'"$.x7f-xff]+)}/s", "=\1?>", $template);
$template = preg_replace("/$var_regexp/es", "$this->addquote('=\1?>')", $template);
$template = preg_replace("/==$var_regexp?>?>/es", "$this->addquote('=\1?>')", $template);
$template = preg_replace("/[nrt]*{templates+([a-z0-9_]+)}[nrt]*/is", "n include('".$this->cache_dir."\1".$this->cache_suffix."'); ?>n", $template);
$template = preg_replace("/[nrt]*{templates+(.+?)}[nrt]*/is", "n include('".$this->cache_dir."\1".$$this->cache_suffix."'); ?>n", $template);
$template = preg_replace("/[nrt]*{evals+(.+?)}[nrt]*/ies", "$this->stripvtags('n \1 ?>n','')", $template);
$template = preg_replace("/[nrt]*{echos+(.+?)}[nrt]*/ies", "$this->stripvtags('n echo \1; ?>n','')", $template);
$template = preg_replace("/[nrt]*{elseifs+(.+?)}[nrt]*/ies", "$this->stripvtags('n } elseif(\1) { ?>n','')", $template);
$template = preg_replace("/[nrt]*{else}[nrt]*/is", "n } else { ?>n", $template);
for($i = 0; $i < $this->nest; $i++) {
$template = preg_replace("/[nrt]*{loops+(S+)s+(S+)}[nr]*(.+?)[nr]*{/loop}[nrt]*/ies", "$this->stripvtags('n if(is_array(\1)) { foreach(\1 as \2) { ?>','n\3n } } ?>n')", $template);
$template = preg_replace("/[nrt]*{loops+(S+)s+(S+)s+(S+)}[nrt]*(.+?)[nrt]*{/loop}[nrt]*/ies", "$this->stripvtags('n if(is_array(\1)) { foreach(\1 as \2 => \3) { ?>','n\4n } } ?>n')", $template);
$template = preg_replace("/[nrt]*{ifs+(.+?)}[nr]*(.+?)[nr]*{/if}[nrt]*/ies", "$this->stripvtags('n if(\1) { ?>','n\2n } ?>n')", $template);
}
$template = preg_replace("/{$const_regexp}/s", "=\1?>", $template);
$template = preg_replace("/ ?>[nr]* /s", " ", $template);
$hash=$this->file_hash($tp_path);
$head_hash="";
$foot_time="";
$this->file_write($this->cache_dir.$file.".tpl",$head_hash.$template.$foot_time);
}
}
$this->error ("The template file does not exist, or there is no operation permission");
function file_read($path,$length=0){
->file_test($path,"r+")){
} /**
*/
path,"w+")){
/**
* Calculate the hash of the file */
function file_hash($path){
return md5_file($path);
}
/**
* Compare the hash values of template files and cached files */
function match_hash($file){
$read_hash=$this->file_read($this->cache_dir.$file.$this->cache_suffix,46);
$html_hash=$this->file_hash($this->tp_dir.$file.$this->tp_suffix);
if(preg_match("/".$html_hash."/i",$read_hash)){
return true;
}
}
function addquote($var) {
return str_replace("\"", """, preg_replace("/[([a-zA-Z0-9_-.x7f-xff]+)]/s", "['\1']", $var));
}
function transamp($str) {
$str = str_replace('&', '&', $str);
$str = str_replace('&', '&', $str);
$str = str_replace('"', '"', $str);
return $str;
}
function stripvtags($expr, $statement) {
$expr = str_replace("\"", """, preg_replace("/=(\$.+?)?>/s", "\1", $expr));
$statement = str_replace("\"", """, $statement);
return $expr.$statement;
}
}
$tp=new mmtp();
$tp->__setdir("./");
$tp->__setcdir("./cache/");
$tp->tp("index1");
$_GET[it]=sdhkadajksdhajdhkajsdhjkasdjkasdhasjdhkjsadhk;
$name=2;
$head="欢迎使用MoMo模板引擎";
include("./cache/index1.tpl");
?>
模板index.html
复制代码
代码如下:
{$head}
模板index1.html 复制代码
代码如下:
{template index}
{if $name==1}
你好 {else} 谢谢 {/if}
这个模板是默默今天下午写的,写的比较仓促,也许存在漏洞,这个版本只是测试版,以后我会逐渐的去完善,先发出来,当作一个前瞻.
以上就介绍了powerpoint 模板 默默简单的写了一个模板引擎,包括了powerpoint 模板方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
