Home  >  Article  >  Backend Development  >  How to generate static pages in php (three functions)

How to generate static pages in php (three functions)

WBOY
WBOYOriginal
2016-07-25 09:05:56960browse
  1. /**

  2. Create directory
  3. */
  4. function makedir($mudir)
  5. {
  6. $file = "./$mudir";
  7. @mkdir($file,0777 );
  8. }

  9. /**

  10. Create the sub-template file path first
  11. */
  12. function writemod($filemodname)
  13. {
  14. $fp=fopen("showmod.shtml","r");
  15. $ str=fread($fp,filesize("showmod.shtml"));
  16. fclose($fp);
  17. $fp=fopen($filemodname,"w");
  18. fwrite($fp,$str);
  19. fclose ($fp);
  20. }

  21. /**

  22. Update respective sub-template files //$modfile is the name of the sub-template
  23. */
  24. function writeweb($content,$web,$modfile)
  25. {
  26. $fp=fopen($modfile," r");
  27. $str=fread($fp,filesize($modfile));
  28. $str=str_replace($content,$web,$str);
  29. fclose($fp);
  30. $fp = fopen($ modfile,"w");
  31. fwrite($fp,$str);
  32. fclose($fp);
  33. }
  34. $m = "00000";
  35. makedir($m);
  36. $ff = $m."/ 0001.shtml";
  37. if(!file_exists($ff))
  38. {
  39. writemod($ff);
  40. }
  41. else
  42. {
  43. echo"already exists";
  44. }
  45. $d="{content6}"; / /Updated content
  46. $dd="";//Content to be updated//Content to be updated
  47. @writeweb($d,$dd,$ff);
  48. ?>

Copy code

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) Reference on how to generate html static pages with php A class written in php to generate static pages Code to generate html static pages from all content in the database How to automatically generate static pages on a virtual host at regular intervals Detailed tutorial on generating static pages with php Solution to the problem that pseudo-static pages cannot be accessed in apache Code written by php about spider crawling records of static pages How to generate static pages using smarty How to generate static pages with PHP Solution to the problem that apache cannot access pseudo-static pages



Statement:
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