.PHP method to generate static html files
- 1, here is a way to use templates!
-
-
- $fp = fopen ("templets.html","a");
- if ($fp){
- $fup = fread ( $fp,filesize("templets.html"));
- $fp2 = fopen ("html.shtml","w");
- if ($fwrite ($fp2,$fup)){
- $fclose ($fp ; >
- Simply write the template into a file and save it as html.html
-
- 2, generate an html file name based on time
-
-
-
-
-
- $content = "This is a file name with date and time. Staticly generate test files for web pages,
- The file name format is generally year, month, day, hour, minute, and second.html";
- $date = date('YmdHis');
- $fp = fopen (date('YmdHis') . '.html',"w");
- //This function can be used to open local or remote file 'w'. The file opening method is writing,
- The file pointer points to the beginning, And set the length of the original file to 0. If the file does not exist,
- create a new file.
- if (fwrite ($fp,$content)){
- //The format is .int fwrite(int fp(file name), string string(content),
- int [length](length)); This function converts the string into string is written to the pointer fp of the file data stream.
- If length is specified, the string of specified length will be written, or written to the end of the string.
- fclose ($fp);//The function is used to close the pointer fp of the opened file.
- Returns true if successful, false if failed.
- die ("Write to template successfully");
- } else {
- fclose ($fp);
- die ("Failed to write to template!");
- }
- echo ($content);
- ?>
-
- 3 , the following is a method to convert file names
-
-
-
- $s_fname = "93e.php";
- $o_fname = "93e.htm";
- ob_end_clean();
- ob_start();
- include( $s_fname);
- $length = ob_get_length();
- $buffer = ob_get_contents();
- $buffer = eregi_replace("r","",$buffer);
- ob_end_clean();
- $fp = fopen($ o_fname,"w+");
- fwrite($fp,$buffer);
- fclose($fp);
- ?>
-
- 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.
-
-
-
- Copy code
-
-
-
-
-
|