Php generates the implementation code of the static HTML document when adding an article. PHP generates static article HTML in batches, but the standard is to generate an HTML article when adding the article and regenerate the HTML article when editing it, when deleting an article, you can also delete PHP to generate static article HTML in batches. However, it is more standard to generate HTML articles when adding an article, re-generate HTML articles when editing, and delete unnecessary HTML articles when deleting the articles. in this case, batch generation is not enough, the following describes how PHP generates static HTML files when adding an article.
Simply add an article form and you will not write it here. the following source code is the source code of the program that accepts the value passed in the form. you can test it first...
The code is as follows:
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 () indicates that the session is enabled. the write-not write relationship is not very large. it is added here according to the PHP Standard writing method.
The second sentence is the file containing the link to the database.
The following $ content = $ _ POST ["content"]; is the content of the form accepted. Accept a few items.
$ Mobanpath = "../moban/moban.html"; this is the template path.
If (file_exists ($ mobanpath): checks whether the template file exists. if yes, perform the following template tag replacement operation.
The next step is to use str_replace to replace the template tag. at the same time, create an HTML file and add it to the database using SQL statements. then return to add. where php adds an article tag, the HTML rules generated here can be added by yourself, for example, generated by time or by Article ID.
...