PHP to add a static HTML article when the implementation code _php tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.