Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php generates static html pages

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "php how to generate static html pages", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php how to generate static html pages" article.

Generally speaking, there are two ways to output html pages using php transformation:

The first is the use of templates.

At present, there are many templates for PHP, including powerful smarty, easy-to-use smarttemplate and so on. Each of these templates has a function to get the output. The way we generate static pages is to take advantage of this function. The advantage of using this method is that the code is clear and readable.

Here I use smarty as an example to show how to generate static pages:

The second method: using the functions of the ob series.

The functions used here are mainly ob_start (), ob_end_flush (), ob_get_content (), where ob_start () means to open the browser buffer. After opening the buffer, all non-header information from the PHP program will not be sent, but will be saved in the internal buffer until you use ob_end_flush (). And the most important function here is ob_get_contents (), which is used to get the contents of the buffer, which is equivalent to the fetch () above, for the same reason.

The second method I choose is to use the functions of the ob series.

I was a little confused when I first looked at this, and then I realized that ob means output buffering, which means output cache.

When you are ready to output, all the data is stored in ob, and after the server parses the php, all the html code to be output to the client is stored in ob. If we want to output a html static page, we just need to take out the cache and write it to a html page.

So the principle is actually very simple.

I use a few functions here, because I'm a beginner of php, and I don't know a lot of functions yet, so here's a little bit of hope that I can help you.

Ob_start (): start to "capture" the cache, which is where you start opening the browser's cache.

Ob_end_flush (): turn off browser caching

Ob_get_content (): read cache contents

Fopen ("File path", "Open Mode") Open File this function has several opening modes, which are described below:

"r" opens read-only and points the file pointer to the file header.

Open the "r +" read-write mode and point the file pointer to the file header.

The "w" write mode is opened, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.

Open "w +" read-write mode, point the file pointer to the file header and cut the file size to zero. If the file does not exist, try to create it.

Fwrite ("file name", "write") to write to the file

Fclose () closes the file

Because there are so many html files I want to convert, there may be hundreds of them, so you can't statically specify the path of fopen. You can set a path variable in which you can store the id and other information sent by users to facilitate the naming of html files. Here is a simple example that I read xml data with php last time.

The above is about the content of this article on "how php generates static html pages". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report