search
HomeBackend DevelopmentPHP TutorialImproved Templates PHP Interpretive Templates Phplib_PHP Tutorial

Before explaining the use of PHP interpretive template Phplib in detail, let me explain why the template system using php tags needs to continue to be improved. In fact, this is mainly because PHP tags are inconvenient for artists. They prefer to use this visual tag directly, such as {title}.

First of all, we modified our previous example to use visual tags. The first step is to change shownews.php to shownews.tpl, and replace the php tags inside with visual tags. The code for shownews.tpl is as follows:

  1. html>
  2. head> 
  3. title>Show news /title>
  4. /head>
  5. body>
  6. {title}
  7. /body>
  8. /html>

The second step, how to achieve the effect of listnews.php? It's actually very simple. I just need to replace {title} directly, right? Therefore, the code of the modified listnews.php is as follows:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?   </span></span></span></li>
<li><span>Include('getnews.php');  </span></li>
<li class="alt"><span>//获取数据   </span></li>
<li><span>echo str_replace('{title}',  </span></li>
<li class="alt"><span>$news,file_get_contents<br>('shownews.tpl'))   </span></li>
<li>
<span class="tag">?></span><span>   </span>
</li>
<li class="alt"><span> </span></li>
</ol>

In fact, the principle of PHP interpretive template Phplib is exactly like this! For example, if we want to use phplib to implement the above functions, we only need to modify listnews.php. The modified code is as follows:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?   </span></span></span></li>
<li><span>Include('getnews.php');  </span></li>
<li class="alt"><span>//获取数据   </span></li>
<li><span>include('template.class.php');   </span></li>
<li class="alt">
<span>$</span><span class="attribute">t</span><span>=</span><span class="attribute-value">new</span><span> Template();   </span>
</li>
<li>
<span>$t-</span><span class="tag">></span><span>set_file(‘shownesw,<br>'shownews.tpl');   </span>
</li>
<li class="alt">
<span>$t-</span><span class="tag">></span><span>set_var('news',$news);   </span>
</li>
<li>
<span>$t-</span><span class="tag">></span><span>parse('out', ‘shownesw');   </span>
</li>
<li class="alt">
<span>$t-</span><span class="tag">></span><span>p('out');   </span>
</li>
<li>
<span class="tag">?></span><span>   </span>
</li>
<li class="alt"><span> </span></li>
</ol>

In addition, about PHP interpretability For the template Phplib area, you can check the corresponding manual.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446061.htmlTechArticleBefore explaining the use of PHP interpretive template Phplib in detail, let’s first explain why the template system using php tags needs to continue to be improved. . In fact, this is mainly because PHP tags are very difficult for artists...
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
PHP5和PHP8的性能和安全性:对比和改进PHP5和PHP8的性能和安全性:对比和改进Jan 26, 2024 am 10:19 AM

PHP是一种广泛应用的服务器端脚本语言,用于开发Web应用程序。它已经发展了多个版本,而本文将主要讨论PHP5和PHP8之间的比较,特别关注其在性能和安全性方面的改进。首先让我们来看看PHP5的一些特点。PHP5是在2004年发布的,它引入了许多新的功能和特性,如面向对象编程(OOP)、异常处理、命名空间等。这些特性让PHP5变得更加强大和灵活,使得开发者能

PHP8.1更新:字符串动态替换函数的改进PHP8.1更新:字符串动态替换函数的改进Jul 09, 2023 pm 08:37 PM

PHP8.1更新:字符串动态替换函数的改进PHP8.1作为一种广泛使用的服务器端脚本语言,经常用于开发网站和Web应用程序。在PHP8.1的更新中,有一个重要的改进是字符串动态替换函数的改进。这个改进使得字符串的操作更加简洁和高效,提高了代码的可读性和可维护性。下面将介绍这个改进,并通过代码示例来说明其用法。在PHP8.0之前,我们使用字符串替换函数str_

PPT蒙版要怎么添加PPT蒙版要怎么添加Mar 20, 2024 pm 12:28 PM

关于PPT蒙版,很多人肯定对它很陌生,一般人做PPT不会将它吃透,而是凑活着可以做出来自己喜欢的就行,所以很多人都不知道PPT蒙版到底是什么意思,也不知道这个蒙版有什么作用,甚至更不知道它可以让图片变得不再那么单调,想要学习的小伙伴们快来了学习学习,为你的PPT图片上添上点吧PPT蒙版吧,让它不再单调了。那么,PPT蒙版要怎么添上呢?请往下看。1.首先我们打开PPT,选择一张空白的图片,之后右键点击【设置背景格式】,纯色选择颜色就行。2.点击【插入】,艺术字,输入字3.点击【插入】,点击【形状】

C++ 模板特化的影响对于函数重载和重写C++ 模板特化的影响对于函数重载和重写Apr 20, 2024 am 09:09 AM

C++模板特化影响函数重载和重写:函数重载:特化版本可提供特定类型不同的实现,从而影响编译器选择调用的函数。函数重写:派生类中的特化版本将覆盖基类中的模板函数,影响派生类对象调用函数时的行为。

如何在 OneNote 中使用模板来提高工作效率如何在 OneNote 中使用模板来提高工作效率Apr 30, 2023 am 11:31 AM

您是否知道使用模板可以提高记笔记的速度以及捕捉重要想法的效率?OneNote有一套现成的模板供您使用。最好的部分是您还可以根据需要设计模板。无论您是学生、企业战士还是从事创造性工作的自由职业者。OneNote模板可用于以适合您风格的结构和格式记录重要笔记。模板可以是记笔记过程的大纲。业余爱好者只是做笔记,专业人士则在模板的帮助下通过结构良好的笔记做笔记并从中汲取联系。让我们看看如何在OneNote中使用模板。使用默认OneNote模板第1步:按键盘上的Windows+R。键入Oneno

PHP电子邮件模板:定制化和个性化您的邮件内容。PHP电子邮件模板:定制化和个性化您的邮件内容。Sep 19, 2023 pm 01:21 PM

PHP电子邮件模板:定制化和个性化您的邮件内容随着电子邮件的普及和广泛应用,传统的邮件模板已经不能满足人们对个性化和定制化邮件内容的需求。现在,我们可以通过使用PHP编程语言来创建定制化和个性化的电子邮件模板。本文将为您介绍如何使用PHP来实现这一目标,并提供一些具体的代码示例。一、创建邮件模板首先,我们需要创建一个基本的邮件模板。这个模板可以是一个HTM

Flask-Bootstrap:为Flask应用程序添加模板Flask-Bootstrap:为Flask应用程序添加模板Jun 17, 2023 pm 01:38 PM

Flask-Bootstrap:为Flask应用程序添加模板Flask是一个轻量级的PythonWeb框架,它提供了一个简单而灵活的方式来构建Web应用程序。它是一款非常受欢迎的框架,但它的默认模板功能有限。要创建富有吸引力的用户界面,需使用其他框架或库。这就是Flask-Bootstrap的用武之地。Flask-Bootstrap是一个基于Twitter

PHP7改进之处:不再出现undefined报错PHP7改进之处:不再出现undefined报错Mar 04, 2024 pm 06:15 PM

PHP7改进之处:不再出现undefined报错PHP7是PHP语言的一个重大版本更新,带来了许多重要的改进和优化。其中一个显著的改进之处是在处理未定义变量时不再出现undefined报错,这为开发者带来了更好的使用体验。在PHP7之前,如果代码中使用了未定义的变量,会导致出现undefined报错,需要开发者通过手动检查或者设置错误报告级别来避免这种情况。

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

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)