以小弟我之代码示例驳斥此等评语,看看什么叫模板引擎。
以我之代码示例驳斥此等评语,看看什么叫模板引擎。。
【既然知道评价中肯,就应该明白差距在哪里了吧,每次运行都进行替换,相当程度上降低了系统性能,这样的模板引擎还有什么优势??】
【的确是有差距的,我看了一下,按照你说的一年多了,你已经累计有5次下载,和1毛钱的运营盈利。跟他这个只是会发个帖子,贴些代码,又没人下载,又没盈利的情况,差距实在太大了。】
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass IndexAction extends YouYaX{ public function index() { header("Content-type: text/html; charset=utf-8"); $this->assign("csdn","csdner,大家中午好") ->assign("head",array("来自","xxx")) ->assign("greet",array("<h2 id="PHP技术">PHP技术</h2>","基础编程","开放资源","framework")) ->assign("foot",array( array("id"=>'1',"foot"=>"这是底部测试1"), array("id"=>'2',"foot"=>"这是底部测试2"), array("id"=>'3',"foot"=>"这是底部测试3") )) ->assign("bye","88,good bye"); $this->display("index.html"); }}?>
- HTML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> <title>welcome YouYaX</title> <center> <table width="400"> <!-- 普通替换 --> <tr> <td>{csdn}</td> </tr> <!-- 一维数组替换 --> <tr> <td> <loop> {head} ———— </loop> 发表在【{greet->1}】</td> </tr> <!-- 一维数组替换 --> <loop> <tr><td>{greet}</td></tr> </loop> </table> <hr> <!-- 二维数组替换 --> <list> <h3 id="foot-foot"> {foot.foot} </h3> </list> <!-- 普通替换 --> {bye} <hr> 比较测试 , 让我们在html中使用PHP吧 , 模板变量上要写上双引号 <br> <?php if( "{bye}"=="88,good bye" ){ echo "<font color=red>看吧 , 果然正确吧, 测试结束,测试者:{head->1}"; }else{ echo "错了"; } ?> </center>
------解决方案--------------------
你晒的不是模板引擎啊
------解决方案--------------------
那么你的模板引擎做了什么呢
- PHP code
//——普通替换 //单个输出数组值 // var_dump($this->array_array);exit; $return=preg_match_all('/\{[^{]*->[^{}]*}/',$txt,$single); if($return){ foreach($single[0] as $v){ $x=strlen($v); $y=$x-2; $z=substr($v,1,$y); //title->0 $z1 = preg_split('/->/', $z, -1, PREG_SPLIT_NO_EMPTY); $txt=str_replace($v,$this->array_array[$z1[0]][$z1[1]],$txt); } } //数组替换 $return=preg_match_all("/\s*(.+?)\s*/s",$txt,$match); if($return){ try{ foreach($match[1] as $lv){ if(eregi("",$lv)){ throw new Exception(htmlspecialchars("<loop>标签不能嵌套<loop>!"),"304"); break; } } }catch(Exception $e){ $this->exception($e); } $result0=$match[0]; //<loop><tr><td>{array}</td></tr></loop> 系列数组 <loop>{array2}</loop> $result1=$match[1]; //<tr><td>{array}</td></tr> 系列数组{array2} //var_dump($result1);exit; foreach($result1 as $r1){ preg_match_all("/\{(.*)\}/",$r1,$match2); $result2=$match2[0][0];//{array} $result3=$match2[1][0];//array $result4=$this->array_array[$result3];//得到的数组 try{ if(!is_array($result4)) throw new Exception(htmlspecialchars("<loop>标签解析出错,仅支持一维数组!"),"306"); /* if(empty($result4)) throw new Exception(htmlspecialchars("<loop>解析一维数组值为空!"),"308"); */ }catch(Exception $e){ $this->exception($e); } $result5=''; // unset($result5); //result5 清零 foreach($result4 as $v){ $result5.=str_replace("{".$result3."}",$v,$r1); } foreach($result0 as $r0){ if(ereg($result2,$r0)) $txt=str_replace($r0,$result5,$txt); } } } //--数组替换 //include替换 $return=preg_match_all("//",$txt,$inc); if($return){ $inc1=$inc[0];//<include file="top.html">系列数组 $inc2=$inc[1];//top.html 系列数组 foreach($inc2 as $v){ if(file_exists($v)){ $sub=file_get_contents($v); foreach($inc1 as $v1){ //区分大小写匹配 if(ereg($v,$v1)){ $txt=str_replace($v1,$sub,$txt); } } }else{ exit("include标签解析出错!"); } } }<div class="clear"> </div></include></loop></loop></loop></loop>

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

AI Hentai Generator
Generate AI Hentai for free.

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



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values of the same keys, making the program design more flexible. array_merge

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

In PHP programming, array is a very important data structure that can handle large amounts of data easily. PHP provides many array-related functions, array_fill() is one of them. This article will introduce in detail the usage of the array_fill() function, as well as some tips in practical applications. 1. Overview of the array_fill() function The function of the array_fill() function is to create an array of a specified length and composed of the same values. Specifically, the syntax of this function is
