. PHP method for generating static html files

Source: Internet
Author: User
. PHP method for generating static html files
. PHP method for generating static html files

  1. 1. The following is a template method!
  2. $ Fp = fopen ("templets.html", "");
  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. $ Fcolse ($ fp2 );
  9. Die ("template written successfully ");
  10. } Else {
  11. Fclose ($ fp );
  12. Die ("failed to write template! ");
  13. }
  14. }
  15. ?>
  16. Simply write the template into a file and save it as HTML.
  17. 2. generate html file names by time
  18. $ Content = "this is a test file for generating a webpage statically based on the date and time file name,
  19. The file name format is generally year, month, day, hour, minute, second. html ";
  20. $ Date = date ('ymdhis ');
  21. $ Fp = fopen (date ('ymdhis '). '.html', "w ");
  22. // This function can be used to open the local or remote file 'W,
  23. The file pointer points to the beginning and sets the length of the original file to 0. If the file does not exist,
  24. Create a new file.
  25. If (fwrite ($ fp, $ content )){
  26. // The format is. int fwrite (int fp (file name), string (content ),
  27. Int [length] (length); this function writes the string to the fp pointer of the file data stream.
  28. If the length is specified, the specified length string is written or the end of the string is written.
  29. Fclose ($ fp); // The function is used to close the fp pointer of an opened file.
  30. True is returned for success, and false is returned for failure.
  31. Die ("template written successfully ");
  32. } Else {
  33. Fclose ($ fp );
  34. Die ("failed to write template! ");
  35. }
  36. Echo ($ content );
  37. ?>
  38. 3. The following is a method for converting file names.
  39. $ S_fname = "93e. php ";
  40. $ O_fname = "93e.htm ";
  41. Ob_end_clean ();
  42. Ob_start ();
  43. Include ($ s_fname );
  44. $ Length = ob_get_length ();
  45. $ Buffer = ob_get_contents ();
  46. $ Buffer = eregi_replace ("r", "", $ buffer );
  47. Ob_end_clean ();
  48. $ Fp = fopen ($ o_fname, "w + ");
  49. Fwrite ($ fp, $ buffer );
  50. Fclose ($ fp );
  51. ?>
  52. In this way, 93e. php can be converted to a static HTML file. Note that the files to be converted cannot contain ob_end_clean (); and ob_start (); statements, and the directory must have write permission.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.