For details about generating static pages in PHP, refer. I will explain in detail the answer to the PHP static page generation. next I will explain in detail the steps for generating static pages in PHP: to study the static page generation, I spent some time explaining in detail about generating static pages in PHP.
Answer
Hello everyone, I will explain in detail the steps for generating static pages in PHP:
In order to study the static generation, I spent a lot of time explaining my experience to you:
The following is my encapsulated create html class:
Class makehtml
{
// + -----------------------------
// + Create an HTML folder in the format
// + -----------------------------
Function c_dir ($ html_type, $ root)
{
$ Htmldata_dir = $ root;
If (! Is_dir ($ htmldata_dir ))
{
If (! Mkdir ($ htmldata_dir, 0777 ))
{
Exit ('Sorry, there is no HTML folder '. $ htmldata_dir.' and you cannot create .');
}
}
Elseif (! Is_writable ($ htmldata_dir ))
{
Exit ('sorry, folder '. $ htmldata_dir.' Do not write ');
}
Return $ htmldata_dir;
}
Function replace_tpl ($ data, $ input_data, $ name)
{// + Replace the variables in the 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)
{// + Generate the html file function create_html ('template', 'static filename ', 'File storage directory', 'submit data ');
$ Htmldata_dir = $ this-> c_dir ($ html_type, $ root); // c_dir ("format", "name ")
$ Modeltpl = $ htmlpage; // you can add a 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. '/'.w.name.'.shtml', 'W + ');
Unset ($ htmldata_dir );
Fwrite ($ fp, $ tpl_data );
Fclose ($ fp );
}
}
?>
Application method:
In combination with database operations, you can create your own database tables.
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 the folder in time format
$ 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 );
// + Indicates the template page, the generated name, the storage folder, and the data information written to the template.
}
?>
Note: Here I just wrote a simple idea. the specific requirements are based on your application. this is the simplest release, and the editors hope to learn.
Continue the study.
Other solutions
The tutorial must be top
Other solutions
You can try it out.
Other solutions
I'm about to learn something like this.
Other solutions
Not only the top, but also the favorite! Haha o (∩ _ ∩) o... haha
Other solutions
Try again...
Other solutions
Good. Yes!
[Img] http://www.phpchina.com/bbs/images/smilies/default/smile.gif#/img]
Other solutions
Favorite ..
Other solutions
I studied DZ code for a long time!
I want to see if they are static!
Haha!
But I have seen several static methods for PHP blogs!
They all look the same!
It's similar to yours!
Hello everyone, next I will explain in detail the steps for generating static pages in PHP: To study this static page generation, I spent...