파워포인트 템플릿을 자동으로 간단하게 템플릿 엔진을 작성했습니다.
엔진 파일
코드 복사 코드는 다음과 같습니다
/**
* Discuz 템플릿 엔진을 기반으로 Momo에서 개발한 OOP 템플릿 엔진으로 템플릿 캐싱을 지원하고 해시 md5 값을 생성할 수 있습니다.由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 "
}
/**~*/
기능 tp($file){
$tp_path=$this->tp_dir.$file.$this->tp_suff ix ;
$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-x ff]* )([[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", "언어var('\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- & gt; addquote ( '& lt;? = \ 1? & gt;')", $ template); template = preg_replace("/==$var_regexp?>?>/es", "$this->addquote('=\1?>')", $template );
$template = preg_replace("/[nrt]*{템플릿 ([a-z0-9_] )}[nrt]*/is", "n include('".$ 이 ->cache_dir."\1".$this->cache_suffix."'); ?>n", $template);
$template = preg_replace("/[nrt]*{템플릿 (. ? )}[nrt]*/is", "n include('".$this->cache_dir."\1".$$this->cache_suffix."'); ?>n", $ 템플릿);
$template = preg_replace("/[nrt]*{평가 (. ?)}[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("/[nt]*{loops (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("/ ? >[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);
}
}
/**
* 파일이 존재하고 읽기 권한이 있는지 확인
* *
* @paramknown_type $path
*/
함수 File_test ($ PATH, $ 메서드) {
If (!File_exists ($ PATH) ||! FOPEN ($ PATHOD)) {
; 🎜> 함수 file_read($path,$length=0){
if(!$this->file _test($path,"r ")){
$fp=@fopen($path," r ");
if($length==0){
$c
}else{
$c
; 경로,"w ")){
$fp=@fopen($path,"w ")
@fwrite($fp,$puts)
fclose($fp); }
}
/**~*/
function file_hash($path){
return md5_file($path);
}
/**
* 템플릿 파일과 캐시 파일의 해시값 비교
* *
*/
함수 match_hash($file){
$read_hash=$this->file_read($this- >cache_dir.$파일 .$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;
}
}
기능 addquote($var) {
return str_replace("\"", """, preg_replace("/[([a-zA-Z0-9_-.x 7f -xff] )]/s", "['\1']", $var));
}
함수 transamp($str) {
$str = str_replace('&', '&', $str);
$str = str_replace('&', '&', $str);
$str = str_replace('"', '"', $str);
$str 반환;
}
기능 stripvtags($expr, $statement) {
$expr = str_replace("\"", """, preg_replace("/=(\$. ?)?> ;/s", "\1", $expr));
$statement = str_replace("\"", """, $statement);
$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
复aze代码
代码如下:
{$head}
模板index1.html
复主代码 代码如下:{template index}
{if $name==1} 你好 {else} 谢谢 {/if}
这个模板是默默今天下午写的,写的比较仓促,也许存在漏洞,这个版本只是测试版,以后나는 당신의 모험을 위해 최선을 다하고 있습니다.
以上就介绍了powerpoint 模板 默默简单的写了一个模板引擎,包括了powerpoint 模板方面 内容,希望对PHP教程有兴趣的朋友有所帮助。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Alipay PHP ...

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

세션 납치는 다음 단계를 통해 달성 할 수 있습니다. 1. 세션 ID를 얻으십시오. 2. 세션 ID 사용, 3. 세션을 활성 상태로 유지하십시오. PHP에서 세션 납치를 방지하는 방법에는 다음이 포함됩니다. 1. 세션 _regenerate_id () 함수를 사용하여 세션 ID를 재생산합니다. 2. 데이터베이스를 통해 세션 데이터를 저장하십시오.

PHP 개발에서 견고한 원칙의 적용에는 다음이 포함됩니다. 1. 단일 책임 원칙 (SRP) : 각 클래스는 하나의 기능 만 담당합니다. 2. Open and Close Principle (OCP) : 변경은 수정보다는 확장을 통해 달성됩니다. 3. Lisch의 대체 원칙 (LSP) : 서브 클래스는 프로그램 정확도에 영향을 미치지 않고 기본 클래스를 대체 할 수 있습니다. 4. 인터페이스 격리 원리 (ISP) : 의존성 및 사용되지 않은 방법을 피하기 위해 세밀한 인터페이스를 사용하십시오. 5. 의존성 반전 원리 (DIP) : 높고 낮은 수준의 모듈은 추상화에 의존하며 종속성 주입을 통해 구현됩니다.

phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? PHPStorm으로 개발할 때 때때로 CLI (Command Line Interface) 모드에서 PHP를 디버그해야합니다 ...

시스템이 다시 시작된 후 UnixSocket의 권한을 자동으로 설정하는 방법. 시스템이 다시 시작될 때마다 UnixSocket의 권한을 수정하려면 다음 명령을 실행해야합니다.

정적 바인딩 (정적 : :)는 PHP에서 늦은 정적 바인딩 (LSB)을 구현하여 클래스를 정의하는 대신 정적 컨텍스트에서 호출 클래스를 참조 할 수 있습니다. 1) 구문 분석 프로세스는 런타임에 수행됩니다. 2) 상속 관계에서 통화 클래스를 찾아보십시오. 3) 성능 오버 헤드를 가져올 수 있습니다.

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...
