PHP generated static article HTML, there are batch generation, but the standard should be added when the article is generated HTML articles, edit and then re-generated HTML articles, delete the article also like to delete the extra HTML article, then batch generation seems a little overwhelmed, Here's how PHP generates static HTML files when you add an article.
Simple Add article form here will not write, the following these source code is to accept the table only son come over the value of the program to execute the source code, you can first take the past test ...
Copy CodeThe 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 () is to open the meaning of the session, write not write the relationship is not very big, here in accordance with the PHP standard to add up.
The second sentence is the file containing the linked database.
The following $ content =$_post["content"); it is the content of the form that is received. There are a few items to accept.
$mobanpath = ". /moban/moban.html "; This is the path to the template.
if (file_exists ($mobanpath)): Verify that the template file exists and, if present, perform the following template label substitution operation.
Further down is the use of str_replace to perform the substitution of template tags, while creating an HTML file, and finally added to the database through SQL statements, Then return to the place where add.php added the article, where the generated HTML rules can be added by themselves, such as by time, or by the article ID.
http://www.bkjia.com/PHPjc/326608.html www.bkjia.com true http://www.bkjia.com/PHPjc/326608.html techarticle PHP generated static article HTML, there are batch generation, but the standard should be added when the article is generated HTML article, edit and then re-generated HTML article, delete the article also like delete ...