Home > Article > Backend Development > Implementation code for generating static HTML articles when php adds articles_PHP tutorial
PHP generates static article HTML, and it can be generated in batches, but the standard method is to generate HTML articles when adding articles, and then regenerate HTML articles when editing. When deleting articles, the excess HTML articles will also be deleted. At this time, batch generation seems a bit overwhelming. Let's introduce how PHP generates static HTML files when adding articles.
I won’t write the simple add article form here. The source code below is the source code of the program that accepts the value passed by the form and executes it. You can take it and test it first. . .
ob_start() means to open the session. It doesn’t matter whether you write it or not. It is added here according to the PHP standard writing method.
The second sentence is the file containing the linked database.
The following $content=$_POST["content"]; is the content of the form accepted. Just accept a few of them.
$mobanpath="../moban/moban.html"; This is the path of the template.
if(file_exists($mobanpath)): Check whether the template file exists. If it exists, perform the following template tag replacement operation.
The next step is to use str_replace to perform the replacement operation of the template tag, and create an HTML file at the same time. Finally, add it to the database through SQL statements, and then return to add.php to add the article bid. Here are the generated HTML rules You can add it yourself, such as generating it based on time, or generating it based on article ID, etc.