PHP generated static article HTML, there are batch generation, but the comparison standard should be in addition to the article when the creation of HTML articles, edit and then regenerate the HTML article, delete the article also like to delete superfluous HTML article, then the batch generation is a bit powerless, Here's how PHP generates static HTML files when adding articles.
Simply add the article form here will not write, the following source code is to accept the table conveys over the value of the program to execute the source code, you can take the past test ...
Copy Code code as follows:
<?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 () is to open the meaning of the session, write-write relationship is not very large, here according to the PHP standard writing added up.
The second sentence is the file that contains the linked database.
The following $ content =$_post[the content of the form. Just accept a few items.
$mobanpath = ". /moban/moban.html "; This is the path to the template.
if (file_exists ($mobanpath)): Verify that the file for the template exists, and if it exists, perform the following template label substitution operation.
Further down is the use of str_replace to perform template tag replacement operations, while creating HTML files, and finally through the SQL statement added to the database, Then go back to the place where the add.php add the article, where the generated HTML rules can be added themselves, such as by time, or by the article ID to generate.