-
- $fp = fopen ("templets.html","a");
- if ($fp){
- $fup = fread ($fp,filesize("templets.html") );
- $fp2 = fopen ("html.shtml","w");
- if ($fwrite ($fp2,$fup)){
- $fclose ($fp);
- $fcolse ($fp2);
- die ("Write template successfully");
- } else {
- fclose ($fp);
- die ("Failed to write template!");
- }
- }
- ?>
-
Copy code
Write the template into a file and save it as html.html.
Method 2, generate html file name by time
-
- $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";
- $date = date('YmdHis');
- $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.
- 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.
- fclose ($fp);//The function is used to close the pointer fp of the opened file. Returns true on success, false on failure.
- die ("Write template successfully");
- } else {
- fclose ($fp);
- die ("Failed to write template!");
- }
- echo ($content);
- ?>
Copy the code
Method 3, convert file name
-
-
$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);
- ?>
-
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
|