Implementation code for generating static HTML articles when php adds articles
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 redundant HTML articles are also deleted. 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. . .
<?php ob_start(); require_once("../inc/conn.php"); $typ=$_POST["typ"]; $title=$_POST["title"]; $content=$_POST["d_content"]; $author=$_POST["author"]; $source=$_POST["source"]; $mobanpath="../moban/moban.html"; if(file_exists($mobanpath)) { $fp=fopen($mobanpath,"r"); $str=fread($fp,filesize($mobanpath)); $str=str_replace("-title-",$title,$str); $str=str_replace("-time-",date("Y-m-d H:i:s"),$str); $str=str_replace("-content-",$content,$str); $str=str_replace("-author-",$author,$str); $str=str_replace("-source-",$source,$str); $foldername=date("Y-m-d"); $folderpath="../newslist/".$foldername; if(!file_exists($folderpath)) { mkdir($folderpath); } $filename=date("H-i-s").".html"; $filepath="$folderpath/$filename"; if(!file_exists($filepath)) { $fp=fopen($filepath,"w"); fputs($fp,$str); fclose($fp); } $filepath=$foldername."/".$filename; $sql="insert into newscontent (newstypeid,newstitle,newspath,newssource,newstime) values ($typ,'$title','$filepath','$source','".date("Y-m-d H:i:s")."')"; mysql_query($sql); header("location:add.php"); } ?>
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 template tags, 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 article bids. The generated HTML rules here can be Add it yourself, such as generating it based on time, or generating it based on article ID, etc.
For more implementation code for generating static HTML articles when PHP adds articles, please pay attention to the PHP Chinese website for related articles!

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Atom editor mac version download
The most popular open source editor
