Home > Backend Development > PHP Tutorial > .PHP method to generate static html files

.PHP method to generate static html files

WBOY
Release: 2016-07-25 09:10:45
Original
922 people have browsed it
.PHP method to generate static html files
  1. 1, here is a way to use templates!
  2. $fp = fopen ("templets.html","a");
  3. if ($fp){
  4. $fup = fread ( $fp,filesize("templets.html"));
  5. $fp2 = fopen ("html.shtml","w");
  6. if ($fwrite ($fp2,$fup)){
  7. $fclose ($fp ; >
  8. Simply write the template into a file and save it as html.html
  9. 2, generate an html file name based on time
  10. $content = "This is a file name with date and time. Staticly generate test files for web pages,
  11. The file name format is generally year, month, day, hour, minute, and second.html";
  12. $date = date('YmdHis');
  13. $fp = fopen (date('YmdHis') . '.html',"w");
  14. //This function can be used to open local or remote file 'w'. The file opening method is writing,
  15. The file pointer points to the beginning, And set the length of the original file to 0. If the file does not exist,
  16. create a new file.
  17. if (fwrite ($fp,$content)){
  18. //The format is .int fwrite(int fp(file name), string string(content),
  19. int [length](length)); This function converts the string into string is written to the pointer fp of the file data stream.
  20. If length is specified, the string of specified length will be written, or written to the end of the string.
  21. fclose ($fp);//The function is used to close the pointer fp of the opened file.
  22. Returns true if successful, false if failed.
  23. die ("Write to template successfully");
  24. } else {
  25. fclose ($fp);
  26. die ("Failed to write to template!");
  27. }
  28. echo ($content);
  29. ?>
  30. 3 , the following is a method to convert file names
  31. $s_fname = "93e.php";
  32. $o_fname = "93e.htm";
  33. ob_end_clean();
  34. ob_start();
  35. include( $s_fname);
  36. $length = ob_get_length();
  37. $buffer = ob_get_contents();
  38. $buffer = eregi_replace("r","",$buffer);
  39. ob_end_clean();
  40. $fp = fopen($ o_fname,"w+");
  41. fwrite($fp,$buffer);
  42. fclose($fp);
  43. ?>
  44. In this way, 93e.php can be converted into a static HTML file. It should be noted that the files to be converted cannot have ob_end_clean(); and ob_start(); statements, and the directory must have write permissions.
  45. Copy code
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