Php generates html file instance code

Source: Internet
Author: User
Optional & lt;/font & gt; & quot ;;

1. The following is a template method!

PHP code
  1. $ Fp = fopen ("templets.html", "");
  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 ("template written successfully ");
  9. } Else {
  10. Fclose ($ fp );
  11. Die ("failed to write template! ");
  12. }
  13. }
  14. ?>

 

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
  1. $ 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 ";
  2. $ Date = date ('ymdhis ');
  3. $ 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.
  4. 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.
  5. 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.
  6. Die ("template written successfully ");
  7. } Else {
  8. Fclose ($ fp );
  9. Die ("failed to write template! ");
  10. }
  11. Echo ($ content );
  12. ?>

 


3. The following is a method for converting file names.
 

 

PHP code
  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. ?>

 


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.