


Use php to generate static html pages (general 2 methods), 2 static methods_PHP tutorial
Use php to generate static html pages (general 2 methods), 2 static methods
Because every time a user clicks on a dynamic link, a data query request will be sent to the server
For a website with potentially millions of visits, this is undoubtedly a huge burden on the server
So converting dynamic data into static html pages has become the first choice to save manpower and material resources
Because I had no corresponding experience before, I thought this technology was very mysterious at first
But after looking at some examples, I found that it is not that complicated (but the information on the Internet is not particularly detailed)
After a morning and afternoon experiment, I finally completed the task. Here are some thoughts and a simple example
I hope the prawns won’t laugh at you
<p> </p> <p>一般来说 用php转换输出html页面有两种办法 引用大虾的文章如下:</p> <p>第一种:利用模板。目前PHP的模板可以说是很多了,有功能强大的smarty,还有简单易用的smarttemplate等。它们每一种模板,都有一个获取输出内容的函数。我们生成静态页面的方法,就是利用了这个函数。用这个方法的优点是,代码比较清晰,可读性好。</p>
Here I use smarty as an example to illustrate how to generate a static page:
<p> </p> <p>第二种方法:利用ob系列的函数。这里用到的函数主要是 ob_start(), ob_end_flush(), ob_get_content(),其中ob_start()是打开浏览器缓冲区的意思,打开缓冲后,所有来自PHP程序的非文件头信息均不会发送,而是 保存在内部缓冲区,直到你使用了ob_end_flush().而这里最重要的一个函数,就是ob_get_contents(),这个函数的作用是获取 缓冲区的内容,相当于上面的那个fetch(),道理一样的。</p>
The second method I chose is to use the ob series of functions
I was a little confused when I first read this. Later I learned that ob means output buffering, which is output buffering
When you are ready to output, all the data is saved in ob. After the server parses the php, all the html codes to be output to the client are stored in ob. If we want to output an html static page, we only need to take out the cache and write it. Just one html page
So the principle is actually very simple
Several functions are used here. Since I am new to PHP and I don’t understand many functions, I will explain them here. I hope it can help everyone
<p> </p> <p>ob_start():开始“捕捉”缓存 也就是从这里开始 打开浏览器的缓存</p> <p>ob_end_flush():关闭浏览器缓存</p> <p>ob_get_content():读取缓存内容</p> <p>fopen(”文件路径”,”打开模式”)打开文件 这个函数的打开模式有好几种 下面介绍几种主要的模式:</p> <p>“r” 只读方式打开,将文件指针指向文件头。</p> <p>“r+” 读写方式打开,将文件指针指向文件头。</p> <p>“w” 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。</p> <p>“w+” 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。</p> <p>fwrite(”文件名称”,”写入内容”) 写入文件</p> <p>fclose() 关闭文件</p>
Since there are many html files I want to convert, there may be hundreds of them, so the path to fopen cannot be statically specified here. You can set a path variable to save the id and other information sent by the user to facilitate the naming of html files. Here is what I combined A simple example of reading xml data in php last time
Reprint: http://www.cnblogs.com/awinlei/archive/2013/03/04/2942962.html

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

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 Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools