Home php教程 php手册 新作模板处理类,有兴趣的可以试试

新作模板处理类,有兴趣的可以试试

Jun 21, 2016 am 09:14 AM
gt quot smart

模板

pfcTemplate 主要特点
1. 高效率
因为程序中分析变量、区块时没有采用正规表达式去做,而采用PHP内置字符串
处理函数来做,所以效率可能会稍高于同类产品

2. 易用性
使用此类只需简单的 创建类实例 -> 添加文件 -> 设置变量/区块 -> [如果有区块则解析]
-> 解析文件 就可以完成. 采用常用的命名方式, 提供通俗易懂的API接口方法.

3. 多级区块处理
通过程序的多级区块处理功能可以实现很多复杂的效果, 可以进行无限层次的套嵌(机器性能允许)

4. 可处理多种来源的模板
模板不一定要做成文件, 可以是来自数据库或其它来源.

$str = read_template_string();

$tpl->set_string('handle1', $str);

5. 变量可定制性

模板中的标识符是可以自行调整的.

如: 将简单变量的标识符定制为 "{/var/}", 只需如下调用:

$tpl->varBegin = '{/';
$tpl->varEnd = '/}';

将区块的定义设置成: "content", 则只需:

$tpl->blockStartBegin = '';

$tpl->blockEndBegin = '';

这样使得本类可以兼容同类产品,如PHPLIB的template、FastTemplate、Smart等.


pfcTemplate说明

我没有在类中加入缓存的功能, 我认为 Smart的缓存实质上还是要用PHP解析的。对于更新快的网站,不适合用SMART

做是大家公认的。但对于更新要求不是很多的网站,用Smart 其实不如在程序中加入生成 html文件的功能。WEB服务器处理

HTML的速度是远比PHP快的。

如果你觉得在解析区块时要加上是否为最好一行的参数不方便, 可修改本类, 在输出时清除最后一个块定义。
但是这样做的结果会比现在的慢一点点。 看你项目的需要折衷吧!



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

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

How to turn on Invert Colors on iPhone 15 How to turn on Invert Colors on iPhone 15 Apr 26, 2023 am 11:16 AM

How to Invert Colors on iPhone Since there are two options for inverting colors on iPhone, you need to try each version - SmartInvert and ClassicInvert. SmartInvert inverts colors on the display except for images, videos, and other functions (shown below). At the same time, ClassicInvert inverts all colors on your iPhone screen. Both settings will invert your screen colors, but ClassicInvert will invert all colors you see, without exception. To invert colors on iPhone: Open Settings from the Home screen. Scroll down and click Accessibility. Click Show from the menu

Microsoft improves Windows 11's Smart App Control, but you might not be able to use it Microsoft improves Windows 11's Smart App Control, but you might not be able to use it Apr 17, 2023 pm 04:40 PM

Microsoft launched SmartAppControl, a Windows 11 security feature, earlier this year. At the time, Microsoft described it as a protection tool that "blocks untrusted or potentially dangerous applications." What was unique about the tool at the time was that it determined whether it should run on a Windows 11 device. SmartAppControl initially runs in evaluation mode; it is in this mode that the application decides whether it should be opened. Microsoft did reveal that users can enable Smart App Control in the App and Browser Controls section of the Windows Security app. According only to Microsoft, SmartAppC

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

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

Comparison: Apple Studio Display vs Samsung Smart Monitor M8 Comparison: Apple Studio Display vs Samsung Smart Monitor M8 May 11, 2023 pm 10:46 PM

Samsung Smart Display M8 vs. Apple Studio Display: Design and Size Since its launch, the Apple Studio Display has been compared to the iMac, consisting of a relatively thin panel on a relatively simple L-shaped stand. It's a well-known and well-loved aesthetic, and Samsung seems to have borrowed it for its presentation. The Samsung SmartMonitor M8 uses the same idea of ​​a thin screen on a stand that looks very similar. Some minor elements are different, such as the small section in the lower left corner that sticks out a bit and the Samsung's chin is very thin, but they seem to be close in terms of basic design. Samsung seems to have taken a lot of inspiration from the 24-inch iMac. Apple's display is smaller than Samsung's

Yaber T2 (Plus): Compact projector with Full HD resolution, battery, JBL sound and smart functions Yaber T2 (Plus): Compact projector with Full HD resolution, battery, JBL sound and smart functions Jun 27, 2024 am 10:31 AM

Yaber products are available on Amazon, and now the company offers a new projector - Yaber T2. The model is available in two versions: the Yaber T2 and the Yaber T2 Plus. The Yaber T2 Plus costs 349 dollars instead of 299 dollars and comes with a TV

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

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提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

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

See all articles