About PHP generate static page detailed coriander _php tutorial

Source: Internet
Author: User
Let me explain in more detail about PHP generation static pages
Answer
Hello everyone, let me explain in detail the steps for PHP to generate a static page:
In order to study this static generation, I spent a lot of time to tell you my experience:
Here is the Create HTML Class I encapsulated:
Class makehtml

{

//+-----------------------------

+ Create HTML folder as formatted

//+-----------------------------



function C_dir ($html _type, $root)

{

$htmldata _dir= $root;

if (!is_dir ($htmldata _dir))

{

if (!mkdir ($htmldata _dir,0777))

{

Exit (' Sorry, there's no HTML folder '. $htmldata _dir. ' and cannot create. ');

}

}

ElseIf (!is_writable ($htmldata _dir))

{

Exit (' Sorry, folder '. $htmldata _dir. ' Not writable ');

}

return $htmldata _dir;

}





function Replace_tpl ($data, $input _data, $name)

{//+ Replace a variable in an HTML template

$data =str_replace ("{title}", $input _data[' title '), $data);

$data =str_replace ("{content}", $input _data[' content '), $data);

return $data;

}

function create_html ($htmlpage, $name, $root, $input _data)

{//+ generates HTML file function create_html (' template ', ' static filename ', ' File store directory ', ' submit data ');



$htmldata _dir= $this->c_dir ($html _type, $root); C_dir ("format", "name")



$MODELTPL = $htmlpage; can add path

$FP =fopen ($MODELTPL, ' R ');

$tpldata. =fread ($fp, FileSize ($MODELTPL));

Fclose ($FP);



$tpl _data= $this->replace_tpl ($tpldata, $input _data, $name);



$FP =fopen ($htmldata _dir. '/'. $name. ' sHTML ', ' w+ ');

unset ($htmldata _dir);

Fwrite ($fp, $tpl _data);

Fclose ($FP);

}

}

?>
Copy Code application Method:
In conjunction with database operations, database tables are built on their own.
Include ("mysql.php");

Include ("create_html.php");

$html =new makehtml (); Instantiate the Create HTML object

$op =$_get["Op"];

if ($op = = ' Insert ')

{

$title =$_post["title"];

$content =$_post["Content"];



$file _path=date ("Y-m", Time ()); Name a folder in the format of time

$query = $DB->query ("INSERT into news values (', ' $title ', ' $content ', ' $times ', ')");

$name = $DB->insert_id ();

$sql _data=array (

' title ' = $title,

' Content ' = $content

);

$html->create_html (' model.html ', $name, $file _path, $sql _data);

+ means: Template page, generated name, store folder, write data to template

}

?>
Copy Code
Note: Here I just wrote a simple idea, the specific needs of the application according to everyone, this is the simplest release, there are editors want to learn the following friends
Continued research.


Other Solutions
The tutorial must be top
Other Solutions
I'm going to drop it.
Other Solutions
Top up and I was about to learn something like this
Other Solutions
Not only to the top, good to collect! Haha o (∩_∩) o ... Ha ha
Other Solutions
Top again ...
Other Solutions
Very good. Support a bit!
[Img]http://www.phpchina.com/bbs/images/smilies/default/smile.gif[/img]
Other Solutions
Collection of. Hehe.
Other Solutions
I studied the long-time DZ code!
Want to see what they are doing static!
Oh!
But I've seen a few static methods of the PHP blog program!
It's all the same!
It's the same as yours!

http://www.bkjia.com/PHPjc/632383.html www.bkjia.com true http://www.bkjia.com/PHPjc/632383.html techarticle Let me explain in more detail about the PHP generation static page Answer Hello everyone, let me explain in detail the steps for PHP to generate a static page: In order to study this static generation, I spent ...

  • Related Article

    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.