Home > Backend Development > PHP Tutorial > Describe in detail the templates and caching of static files generated by PHP

Describe in detail the templates and caching of static files generated by PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 09:05:48
Original
894 people have browsed it
  1. Create TABLE `bihtml` (
  2. `id` int(11) NOT NULL auto_increment,
  3. `szdtitle` varchar(16) NOT NULL,
  4. `szdcontent` text NOT NULL,
  5. PRIMARY KEY (`id`)
  6. ) TYPE
Copy code

Get the current ID and import the template:

  1. ob_start();

  2. $id=_POST['id']
  3. if(!isset($id)&is_integer($id))
  4. {
  5. @$ db=new mysqli('localhost','root','admin','bihtml');
  6. $result=$db->fetch_one_array("select * from szd_bi where id='$id'");
  7. if (!emptyempty($result))
  8. {
  9. $tmp->assign(array(
  10. "Szdtitle",htmlspecialchars($result['titles']),
  11. "Szdcontent",$result['titles'])) ;
  12. }
  13. $tpl->display('default_1.tpl');
  14. $this_my_f= ob_get_contents(); //The key here
  15. ob_end_clean();
  16. $filename = "$id.html";
  17. if( tohtmlfile_cjjer($filename,$this_my_f))
  18. echo "Generate successfully $filename";
  19. else
  20. echo "Generate recognition";
  21. }
  22. }

  23. //Write out the process of generating the file Function

  24. function tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content)
  25. {
  26. if (is_file ($file_cjjer_name)){
  27. @unlink ($file_cjjer_name);
  28. }
  29. $cjjer_handle = fopen ($file_cjjer_name,"w");
  30. if ( !is_writable ($file_cjjer_name)){
  31. return false;
  32. }
  33. if (!fwrite ($cjjer_handle,$file_cjjer_content)){
  34. return false;
  35. }
  36. fclose ($cjjer_handle); //Close pointer
  37. return $file_cjjer_name;
  38. }

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



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template