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 ...