-
- Create TABLE `bihtml` (
- `id` int(11) NOT NULL auto_increment,
- `szdtitle` varchar(16) NOT NULL,
- `szdcontent` text NOT NULL,
- PRIMARY KEY (`id`)
- ) TYPE
Copy code
Get the current ID and import the template:
-
-
ob_start(); - $id=_POST['id']
- if(!isset($id)&is_integer($id))
- {
- @$ db=new mysqli('localhost','root','admin','bihtml');
- $result=$db->fetch_one_array("select * from szd_bi where id='$id'");
- if (!emptyempty($result))
- {
- $tmp->assign(array(
- "Szdtitle",htmlspecialchars($result['titles']),
- "Szdcontent",$result['titles'])) ;
- }
- $tpl->display('default_1.tpl');
- $this_my_f= ob_get_contents(); //The key here
- ob_end_clean();
- $filename = "$id.html";
- if( tohtmlfile_cjjer($filename,$this_my_f))
- echo "Generate successfully $filename";
- else
- echo "Generate recognition";
- }
- }
//Write out the process of generating the file Function
- function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content)
- {
- if (is_file ($file_cjjer_name)){
- @unlink ($file_cjjer_name);
- }
- $cjjer_handle = fopen ($file_cjjer_name,"w");
- if ( !is_writable ($file_cjjer_name)){
- return false;
- }
- if (!fwrite ($cjjer_handle,$file_cjjer_content)){
- return false;
- }
- fclose ($cjjer_handle); //Close pointer
- return $file_cjjer_name;
- }
-
Copy code
4. Instructions
1) It is recommended to generate a static page when adding data, and consider recording the generated file ranking and path.
2) PHP mainly uses ob_starts() and ob_get_contents to generate static pages. Of course, you can also consider calling up the database to directly replace the variables in the template.
3) The template engine mainly uses smarty.
Articles you may be interested in:
Three methods and code details for generating static pages in PHP
Example of php generating static page function (php2html)
How to generate static pages in php (three functions)
A class written in php to generate static pages
How to automatically generate static pages on a virtual host at regular intervals
Two ways to generate static files with php
Detailed tutorial on generating static pages with php
Principle analysis of php generating static html files
How to generate static pages using smarty
Understand the principle of php generating static HTML files
How to generate static pages with PHP
Three ways to generate static html files with php
|