- $fp = fopen ("templets.html", "a");
- if ($fp) {
- $fup = Fread ($fp, FileSize ("templets.html"));
- $FP 2 = fopen ("html.shtml", "w");
- if ($fwrite ($fp 2, $fup)) {
- $fclose ($FP);
- $fcolse ($fp 2);
- Die ("Write template Success");
- } else {
- Fclose ($FP);
- Die ("Write template failed!");
- }
- }
- ?>
Copy CodeWrite the template into a file and save it as html.html. Method 2, generate HTML file names by time
- $content = "This is a test file of a statically generated Web page with datetime as the file name, and the file name format is usually date and time. html";
- $date = Date (' Ymdhis ');
- $fp = fopen (the date (' Ymdhis '). '. html ', ' W ');//This function can be used to open local or remote file ' W ' Open file method for writing, the file pointer refers to the beginning, and the length of the original file is set to 0. If the file does not exist, a new file is created.
- if (fwrite ($FP, $content)) {//the format is. int fwrite (int fp (file name), string string (contents), int [length]), and this function writes string strings to the file stream's pointer f P on. If the length is specified, the specified length string is written, or the end of the string is written.
- Fclose ($FP);//function to close a pointer to an already opened file FP. The success returns True, and False if it fails.
- Die ("Write template Success");
- } else {
- Fclose ($FP);
- Die ("Write template failed!");
- }
- Echo ($content);
- ?>
Copy CodeMethod 3, convert the 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 CodeThis allows the 93e.php to be converted into a static HTML file. Note: You cannot have Ob_end_clean (), and Ob_start () statements in the file to be converted. The directory must have write permissions. You may be interested in the article: three ways to generate static pages in PHP and the code in detail PHP generates static page functions (php2html) example PHP method for generating static pages (three functions) The template of PHP generated static files and cache PHP write a static page generated on the class virtual host on a regular basis to automatically generate static page method PHP two ways to generate static files PHP generate static HTML file in a detailed tutorial php generation of Smarty Static page method |