Home > Backend Development > PHP Tutorial > Three ways to generate static html files in php

Three ways to generate static html files in php

WBOY
Release: 2016-07-25 08:51:35
Original
999 people have browsed it
  1. $fp = fopen ("templets.html","a");
  2. if ($fp){
  3. $fup = fread ($fp,filesize("templets.html") );
  4. $fp2 = fopen ("html.shtml","w");
  5. if ($fwrite ($fp2,$fup)){
  6. $fclose ($fp);
  7. $fcolse ($fp2);
  8. die ("Write template successfully");
  9. } else {
  10. fclose ($fp);
  11. die ("Failed to write template!");
  12. }
  13. }
  14. ?>
Copy code

Write the template into a file and save it as html.html.

Method 2, generate html file name by time

  1. $content = "This is a test file for statically generated web pages with date and time as the file name. The file name format is generally year, month, day, hour, minute and second. html";
  2. $date = date('YmdHis');
  3. $fp = fopen (date('YmdHis') . '.html',"w");//This function can be used to open local or The remote file 'w' opens the file for writing, the file pointer points to the beginning, and the length of the original file is set to 0. If the file does not exist, create a new file.
  4. if (fwrite ($fp,$content)){//The format is .int fwrite(int fp(file name), string string(content), int [length](length)); This function writes the string string Enter the pointer fp of the file data stream. If length is specified, the string of the specified length will be written, or written to the end of the string.
  5. fclose ($fp);//The function is used to close the pointer fp of the opened file. Returns true on success, false on failure.
  6. die ("Write template successfully");
  7. } else {
  8. fclose ($fp);
  9. die ("Failed to write template!");
  10. }
  11. echo ($content);
  12. ?>
Copy the code

Method 3, convert file name

  1. $s_fname = "93e.php";

  2. $o_fname = "93e.htm";
  3. ob_end_clean();
  4. ob_start();
  5. include($s_fname );
  6. $length = ob_get_length();
  7. $buffer = ob_get_contents();
  8. $buffer = eregi_replace("r","",$buffer);
  9. ob_end_clean();

  10. $fp = fopen($o_fname,"w+");

  11. fwrite($fp,$buffer);
  12. fclose($fp);
  13. ?>

Copy the code

This is it You can convert 93e.php into a static HTML file. Note: There cannot be ob_end_clean(); and ob_start(); statements in the file to be converted. The directory must have write permissions. 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) Details on templates and caching of static files generated by PHP 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 Smarty’s method to generate static pages



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