PHP技巧:详解phplib模板使用过程及运行原理
index.htm文件内容:
以下为引用的内容: {SortList} index.php内容:
|
详细分析过程:
一、$t->set_file ("Index", "index.htm"); $this->file[index] = index.htm
二、$t->set_block("Index", "RowSort", "RowsSort");
1、载入index文件index.htm内容并赋给变量$this->varvals[index]
2、$str = $this->varvals[index]获取模板文件内容
3、用preg_match_all函数来匹配模板文件中对应的block(RowSort)里的内容,并存储到$m[1][0]中
4、lock(RowSort)里的内容(包括头和尾)替换为{RowSort}
5、变量$this->varvals[RowSort] = $m[1][0] , $this->varkeys[RowSort] = /{RowSort}/
6、变量$this->varvals[index] = $str(内容已发生改变,见第4步) , $this->varkeys[index] = /{index}/
三、$t->set_var("SortList", $list_sort);
设置$this->varvals[SortList] = $list_sort
设置$this->varkeys[SortList] = /{SortList}/
四、$t->parse("RowsSort", "RowSort", true);(此操作根据sort大小重复进行)
1、利用subst函数把$this->varvals数组中的所有变量值对其中可能含有的特殊字符\和$进行处理(\和$分别替换为\\和\$,这样可以确保下一步的preg_replace不出现意外),并赋给$varvals_quoted数组
2、$str = $this->varvals[RowSort]
3、我们可以看出此时$str中含有一个{SortList},而由三:$this->varkeys[SortList] = /{SortList}/,$this->varvals[SortList] = $list_sort
4、可见经过preg_replace我们得到的$str是已经解析了PHP模板变量{SortList}之后的内容了,返回$str
5、给$this->varvals[RowSort]进行延续赋值 //这里有个问题大家可能会考虑到就是显示的时候最开始那个{RowSort}未被解析,不用担心,phplib有finish函数会对它根据你的要求进行处理
五、$t->parse("OUT", "Index");
1、可以看出,这时$this->varvals[index]中有一个PHP模板变量要进行解析,即{RowSort}
2、而在前面几步中,我们已经把$this->varvals[RowSort]的内容解析好
3、这样以来,我们把全部PHP模板变量均已解析后的内容赋给变量$this->varvals[OUT]
六、$t->p["OUT"];
显然phplib中p函数即为输出函数,我们直接把$this->varvals[OUT]输出即可
//这里要注意的是输出之前有个phplib自动进行的动作,就是对未被解析的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



index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

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

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

PHP source code running problem: Index error resolution requires specific code examples. PHP is a widely used server-side scripting language that is often used to develop dynamic websites and web applications. However, sometimes you will encounter various problems when running PHP source code, among which "index error" is a common situation. This article will introduce some common causes and solutions of index errors, and provide specific code examples to help readers better deal with such problems. Problem Description: When running a PHP program

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.

The index in MySQL means index. It is a data structure used to speed up the query of database tables. The index can be compared to the catalog of a book. It stores the values of specific columns in the table and the corresponding row positions, making the database more efficient. Locate and access data quickly. The function of the index is to improve query efficiency. Without an index, the database needs to scan the entire table row by row to find matching data. This method will be very time-consuming in large tables. With an index, the database can The required data rows are quickly located in the order, which greatly improves the query speed.
