search
HomeBackend DevelopmentPHP TutorialDetailed introduction to the functions of PHP templates_PHP tutorial
Detailed introduction to the functions of PHP templates_PHP tutorialJul 20, 2016 am 10:57 AM
phpintroduceaboutFunctionDiscoverexiststudyustemplateofKnowledgedetailedlanguagedifficult

When learning the PHP language, we found that the knowledge about PHP templates is a little difficult to master. Today we will give you a detailed analysis of the specific functions of PHP templates to deepen your understanding of the PHP language.

In fact, the most important thing is to suit your own project needs, not your own habits. For example, if a company's promotional website does not have many visits or updates, it will be used the same, or even not used. Direct PHP + HTML writing may be the fastest. There is nothing wrong with it. But if it is a news system or a content publishing system, it is very necessary to use template technology. Because they all have one thing in common. , that is, there is a type of page that needs to use the same style of page design. According to the actual situation, such as the size of the visits, the urgency of the project and the programmer's proficiency in template technology, choose the template technology that is most suitable for the project. This is the first choice. "

"I have been exposed to templates since I started learning PHP. I use the smarty template engine (officially supported and powerful). The longer I use it, the more I feel that templates are a good thing. As long as it involves things displayed on the page, I will use templates to write them. It always feels awkward to write programs without templates. I think other phpers will have the same feeling, because the original intention of PHP template design is to separate the code and the page and process them separately. After all, no one wants to write code and process the page at the same time. ”

“Some people say that SMARTY is already very good, but others say that SUPERTPL is better, and some people prefer PHPLIB. I think each template has its own advantages and disadvantages. The key is up to you. What is needed for the project and what is best to use! "[from feifengxlq]"There is definitely nothing wrong with using templates. I initially used PHPLIB. After using it for a while, I felt it was too simple. Each template variable had to be replaced by code, and each template referenced had to write a line. So I gave up on the code (maybe PHPLIB has a batch processing function, I'm too new to know). Later, when I used plog to build a website, I came into contact with smarty. I felt that smarty was too large and could indeed speed up the development progress, but many functions were not actually used, so In the end, I wrote my own template engine. The function to be implemented by the template is very simple, which is the replacement function of a template variable, plus the include other templates and the foreach block operation function. "

"I still use PHPLIB, but based on my own experience and needs, I will write some functions or classes to encapsulate some of the most commonly used template output processing. "[From seraph]"I use my own PHP template, and I have to write template parsing code, which is tiring. I chose to use an existing excellent template. "[From Bantu] "I have seen some very powerful people on other forums not using templates... Maybe they are not at that level... Personally, I feel it is better to use templates... At least they can divide the work... and speed up development. . Use your own template? I don’t think it’s necessary... Just use the ready-made ones. Add some practical functions that you want to learn based on the ready-made ones. "[From Phzzy] "I don't use a template engine, but I still use templates, just different from yours. Because the template engine is too slow, it feels difficult to use. "

"I use a third party, preferably open source. As for which one to use, it depends on personal preference. ” [from leeyupeng] “I still tend to use my own templates that are simple and practical. "[From Yuhi] "Due to performance considerations, I generally do not use universal templates. I will make some trade-offs based on the actual situation, which has certain limitations. "[From Ben] "Decide whether to use templates or not, and what templates to use, based on your needs. It never hurts to be flexible. "[From xlmo] "I personally like simple and fast templates. You can consider using ready-made PHP templates. However, I usually optimize them based on the actual project and delete some functions that are not used. ”

Using templates generally does not cause bottlenecks. As for the efficiency, it mainly affects the following points:

1. After the program and template are separated, a file becomes If there are two or more, then reading the IO of the template is also time-consuming

2. Parsing the template is relatively complicated, generally requiring N preg_match, preg_replace and other functions to process or replace

3. Loading and replacing templates obviously requires more memory than not using templates

So to improve efficiency, pay attention to the following points:

1. Choose a template parsing program that supports compilation and caching. This has the most obvious benefit on performance. It depends on how you apply it flexibly.

2. The parsing program should be as simple as possible. It will be convenient to use if all functions are included. , the performance is also poor

3. When making HTML template pages, follow simple principles, such as making them according to xhtml standards, and try not to split a page into many templates and then include them. ”

“If you use a template, I think it’s better to write one yourself if you have the ability. This is also an exercise. But if you want to use it, I think Xiaoqiang is very good. You can edit it visually.” [from jejwe] “I personally also think that template files The visual editability is very important. It cannot be required that the production of template pages must also have a certain program development foundation. "[From seraph]" Detailed analysis of specific problems, whether to use PHP templates, choose already formed excellent template classes or write them yourself. , everything is based on specific project development, you can’t settle on one.” [From Deepseath] “I feel that the existing templates are not perfect enough, or have few functions, or are slow, so it is better to do it yourself.”

“To summarize, PHP templates can make your code context clearer and the structure more rational. However, the development of PHP templates will always be much slower than the rapid development of PHP applications. In this case, it will It affects the development of PHP applications. For every PHPer, no PHP template is the most suitable and perfect for him, because the so-called PHP template is a popular thing and is not personal.

Therefore, if you can fully understand the advantages and disadvantages of templates and the principles of PHP application based on a clear understanding of PHP characteristics and applications, PHPer can get the PHP templates you need that suit your own development style. This is also the most important thing about PHP. One of the ideas is that PHP only provides methods and approaches, not the final solution. Therefore, templates, like PHP applications and products, can be transformed into their own PHP templates because the creator's ideas are embedded in them. 🎜>Limited to various constraints, such as time and experience, you may think that it is very difficult to make your own PHP template. In fact, what you need is not to reconstruct a PHP template, but to choose a PHP that is closest to you. The template needs to be transformed. Because PHP needs inheritance and innovation. Of course, make your own PHP template and implement it step by step, and integrate the latest ideas and concepts in a timely manner

Personal PHP can start from the details. Start with your own development habits where needed. The PHPer team can work together to localize PHP templates, which is especially practical for companies. Even if you just modify a symbol in the PHP template, just a symbol can tell you. After you modify it, it belongs to you. The most important thing is that your own PHP template will never be fixed. It will grow with you and become a witness of your PHP journey

<.>PHP does not need to be very proficient in syntax; PHP does not need you to develop numerous libraries yourself; PHP does not need you to worry about performance, stability and other characteristics of the language itself; what PHP needs is your logic; It’s your creativity; what PHP needs is your mind!”


http://www.bkjia.com/PHPjc/445772.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445772.htmlTechArticleWhen learning the PHP language, we found that the knowledge about PHP templates is a little difficult to master. Today we will give you a detailed analysis of the specific functions of PHP templates to deepen...
Statement
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
详解win11能否运行PUBG游戏详解win11能否运行PUBG游戏Jan 06, 2024 pm 07:17 PM

pubg又称绝地求生,是一款非常经典的射击大逃杀类型游戏,从2016年火爆以来一直拥有非常多的玩家。在最近的win11系统推出后,就有不少玩家想要在win11上游玩它,下面就跟着小编来看看win11是否可以玩pubg吧。win11能玩pubg吗:答:win11可以玩pubg。1、在win11推出之初,因为win11需要开启tpm的缘故,所以导致很多玩家被pubg封号处理了。2、不过后来根据玩家的反馈,蓝洞方面已经解决了这个问题,目前已经可以在win11中正常玩pubg了。3、如果大家遇到了pub

Python函数介绍:exec函数的介绍及示例Python函数介绍:exec函数的介绍及示例Nov 03, 2023 pm 02:09 PM

Python函数介绍:exec函数的介绍及示例引言:在Python中,exec是一种内置函数,它用于执行存储在字符串或文件中的Python代码。exec函数提供了一种动态执行代码的方式,使得程序可以在运行时根据需要生成、修改和执行代码。本文将介绍exec函数的使用方法,并给出一些实际的代码示例。exec函数的使用方法:exec函数的基本语法如下所示:exec

i5处理器是否能装win11详细介绍i5处理器是否能装win11详细介绍Dec 27, 2023 pm 05:03 PM

i5是英特尔旗下的一系列处理器,拥有到现在11代i5的各种不同版本,每一代都有着不同性能。因此对于i5处理器是否能够安装win11,还需要看是第几代的处理器,下面就跟着小编一起来分别了解一下吧。i5处理器能装win11吗:答:i5处理器能装win11。一、第八代及之后的i51、第八代及后续的i5处理器是能够满足微软的最低配置需求的。2、因此我们只需要进入微软网站,下载一个“win11安装助手”3、下载完成后,运行该安装助手,根据提示进行操作就可以安装win11了。二、第八代之前的i51、第八代之

edge快捷键的介绍edge快捷键的介绍Jul 12, 2023 pm 05:57 PM

在如今快捷的生活,为了提高工作效率,快捷键是必不可少的工作需求。快捷键是指按键或按键组合,可提供另一种方式来执行通常使用鼠标执行的操作。那么edge快捷键有哪些呢?edge快捷键的功能又有哪些呢?下面小编整理了一份edge快捷键的介绍,感兴趣的朋友们快来看看吧!Ctrl+D:将当前页面添加到收藏夹或阅读列表Ctrl+E:在地址栏中执行搜索查询Ctrl+F:在页面上查找Ctrl+H:打开历史记录面板Ctrl+G:打开阅读列表面板Ctrl+I:打开收藏夹列表面板(测试好像不起作用)Ctrl+J:打开

Java语言中的数学模型介绍Java语言中的数学模型介绍Jun 10, 2023 am 11:57 AM

Java语言是一种高级编程语言,非常适合用于数学模型的构建和分析。数学模型是数学概念在现实世界中的应用,它们通常用于解决实际问题,例如预测未来趋势、优化生产和制造等。本文将介绍Java语言中常见的数学模型及其应用。线性规划线性规划是一种优化方法,在解决企业最优决策、资源配置以及生产计划等问题中广泛应用。在Java语言中,可以使用ApacheCommons

Python函数介绍:zip函数的介绍及示例Python函数介绍:zip函数的介绍及示例Nov 03, 2023 pm 02:02 PM

Python函数介绍:zip函数的介绍及示例Python是一种高级语言,它提供了许多有用的函数来帮助开发人员快速地编写程序。其中一个函数就是zip函数。Zip函数是Python中的内置函数之一,它可以接受一组可迭代对象(包括列表、元组、集合和字典等),并返回一个由这些可迭代对象中的元素按顺序成对组成的元组。Zip函数可以用于多种情况,例如:1.将两个列表的元

windows7旗舰版激活方法介绍windows7旗舰版激活方法介绍Jul 09, 2023 pm 08:05 PM

win7系统是微软经典的操作系统,其中win7旗舰版系统最为受欢迎,但是安装之后需要激活才能使用全部的功能。那么该如何激活win7系统呢?常见的方法就是win7激活工具或者密钥激活,下面小编就教下大家windows7旗舰版激活方法。我们以常用的win7激活工具,win7activation工具为例,具体的使用方法如下:1、首先在电脑上搜索并下载好win7activation工具软件包,解压后得到win7activation.exe的文件。鼠标右键点击exe文件,在弹出的菜单栏中点击以管理员身份运

PHP函数介绍:strtr()函数PHP函数介绍:strtr()函数Nov 03, 2023 pm 12:15 PM

PHP函数介绍:strtr()函数在PHP编程中,strtr()函数是一个非常有用的字符串替换函数。它用于将字符串中的指定字符或字符串替换为其他字符或字符串。本文将介绍strtr()函数的用法,并给出一些具体的代码示例。strtr()函数的基本语法如下:strtr(string$str,array$replace)其中,$str是要进行替换操作的原始字

See all articles

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software