Optional & lt;/font & gt; & quot ;;
1. The following is a template method!
PHP code
-
- $ Fp = fopen ("templets.html", "");
- If ($ fp ){
- $ Fup = fread ($ fp, filesize ("templets.html "));
- $ Fp2 = fopen ("html.shtml", "w ");
- If ($ fwrite ($ fp2, $ fup )){
- $ Fclose ($ fp );
- $ Fcolse ($ fp2 );
- Die ("template written successfully ");
- } Else {
- Fclose ($ fp );
- Die ("failed to write template! ");
- }
- }
- ?>
Php $ 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 ("successfully written to template");} else {fclose ($ fp); die ("failed to write to template! ") ;}}?>
Simply write the template into a file and save it as HTML.
2. generate html file names by time
PHP code
-
- $ Content = "this is a test file for generating static web pages with the file name as the daily time. the file name format is generally year, month, day, minute, second. html ";
- $ Date = date ('ymdhis ');
- $ Fp = fopen (date ('ymdhis '). '.html ', "w"); // This function can be used to open a local or remote file in the 'W' open file mode. the file pointer points to the beginning, 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 (content), int [length] (length); this function writes the string to the fp pointer of the file data stream. If the length is specified, the specified length string is written or the end of the string is written.
- Fclose ($ fp); // The function is used to close the fp pointer of an opened file. True is returned for success, and false is returned for failure.
- Die ("template written successfully ");
- } Else {
- Fclose ($ fp );
- Die ("failed to write template! ");
- }
- Echo ($ content );
- ?>
3. The following is a method for converting file names.
PHP code
-
- $ 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 is converted to a static HTML file.
Note that the files to be converted cannot contain
Ob_end_clean (); and ob_start (); statements.
The directory must have the write permission.