Home >Backend Development >PHP Tutorial >Detailed tutorial on generating static pages in php
PHP processing: templatetest.php
Template parsing processing, that is, filling (content) with the results obtained after PHP script parsing and processing Template processing process. Usually with the help of template classes. Currently, the more popular template parsing classes include phplib, smarty, fastsmarty and so on. The principle of template parsing processing is usually replacement. There are also some programmers who are accustomed to putting judgment, looping and other processing into template files and processing them with parsing classes. The typical application is the block concept, which is simply a loop processing. The PHP script specifies the number of loops, how to loop through, etc., and then the template parsing class implements these operations. How to generate static files with PHP. PHP generating static pages does not refer to PHP’s dynamic parsing and outputting HTML pages, but refers to using PHP to create HTML pages. At the same time, because of the non-writable nature of HTML, if the HTML we create is modified, it needs to be deleted and regenerated. (Of course, you can also choose to use regular rules to modify it, but I personally think that it is faster than deleting and regenerating it, which is not worth the gain.) PHP fans who have used PHP file operation functions know that there is a file operation function fopen in PHP, which is to open a file. If the file does not exist, try to create it. This is the theoretical basis on which PHP can be used to create HTML files. As long as the folder used to store HTML files has write permission (ie permission definition 0777), the file can be created. (For UNIX systems, Win systems do not need to be considered.) Taking the above example as an example, if we modify the last sentence and specify to generate a static file named test.html in the test directory:
Reference for solutions to common problems: 1. Article list issues: Create a field in the database and record the file name. Each time a file is generated, the automatically generated file name is stored in the database. For recommended articles, just point to the page in the designated folder where the static files are stored. Use PHP operations to process the article list, save it as a string, and replace this string when generating the page. For example, add the tag {articletable} to the table where the article list is placed on the page, and in the PHP processing file:
Second, paging problem. If we specify pagination, there will be 20 articles per page. There are 45 articles in a certain sub-channel list according to the database query. First, we obtain the following parameters through query: 1, the total number of pages; 2, the number of articles per page. The second step, for ($i = 0; $i
Other data generation, data input and output checking, paging content pointing, etc. can be added to the page as appropriate. Articles you may be interested in: Three methods and code details for generating static pages in PHP Example of php generating static page function (php2html) How to generate static pages in php (three functions) Details on templates and caching of static files generated by PHP A class written in php to generate static pages How to automatically generate static pages on a virtual host at regular intervals Two ways to generate static files with php Principle analysis of php generating static html files How to generate static pages using smarty Understand the principle of php generating static HTML files How to generate static pages with PHP Three ways to generate static html files with php |