Sample code for parsing PHP generated HTML files _php tutorial

Source: Internet
Author: User
Learn PHP generates HTML file 1, below using a method of template!

  1. < ? PHP
  2. $ FP = fopen ("templets.html", "a");
  3. if ($fp) {
  4. $ fup = fread ($FP, FileSize
    ("templets.html"));
  5. $ FP2 = fopen ("html.shtml", "w");
  6. if ($fwrite ($fp 2, $fup)) {
  7. $fclose ($FP);
  8. $fcolse ($fp 2);
  9. Die ("Write template Success");
  10. } else {
  11. Fclose ($FP);
  12. Die ("Write template failed!");
  13. }
  14. }
  15. ?>
 
 
  1. < ? PHP
  2. $ FP = fopen ("templets.html", "a");
  3. if ($FP)
  4. {$fup = fread ($fp, FileSize ("templets.html"));
  5. $ FP2 = fopen ("html.shtml", "w");
  6. if ($fwrite ($fp 2, $fup))
  7. {$fclose ($FP);
  8. $fcolse ($fp 2);
  9. Die ("Write template Success"); }
  10. else {fclose ($fp);
  11. Die ("Write template failed!");
  12. }
  13. }
  14. ?>

Simply write the template into a file and save as Html.html

PHP generates HTML files 2, generates HTML file names by time

 
 
  1. < ? PHP
  2. $ content = "This is a date time as a filename
    The static generated Web page of the test file, file name format one
    < font color= #ff0000 > dd/DD
    .html</font> ";
  3. $ Date Date = Date (' Ymdhis ');
  4. $ FP = fopen (Date (' Ymdhis '). '. html ', ' W ');
    This function can be used to open a local or remote file ' W '
    Open file mode is write, file pointer refers to the beginning,
    and set the length of the original file to 0. If the file does not exist, a new file is created.
  5. if (fwrite ($FP, $content)) {
    The format is. int fwrite (int fp (file name),
    String string (contents), int [length]
    (length)); This function writes string strings to a file
    Data flow on the pointer FP. If the length is specified,
    is written to the specified length string, or to the end of the string.
  6. Fclose ($FP);//function to close a text that has already been opened
    The widget's pointer fp. The success returns True, and False if it fails.
  7. Die ("Write template Success");
  8. }
  9. else {
  10. Fclose ($FP);
  11. Die ("Write template failed!");
  12. }
  13. Echo ($content);
  14. ?>

 
 
  1. < ? PHP $ content = "This is a date time as a filename
    The static generated Web page of the test file, the file name format is generally
  2. < font color= #ff0000 > Month day .html</font> " ;
  3. $ Date Date = Date (' Ymdhis ');
  4. $ FP = fopen (Date (' Ymdhis '). '. html ', ' W ');
  5. This function can be used to open a local or remote file ' W '
    Open file mode is write, file pointer refers to the beginning,
    and set the length of the original file to 0. If the file does not exist, a new file is created.
  6. if (fwrite ($FP, $content))
  7. {//format is. int fwrite (int fp (filename),
    String string (contents), int [length] (long));
  8. This function writes string strings to the pointer FP on the file stream.
    If length is specified, the specified length string is written,
    or write to the end of the string. Fclose ($FP);
  9. The function is used to close a pointer to an already opened file FP.
    The success returns True, and False if it fails.
  10. Die ("Write template Success"); }
  11. else {fclose ($fp); Die ("Write template failed!");
  12. }
  13. Echo ($content); ?>

PHP generates HTML file 3, below is a way to convert the file name

 
 
  1. < ? PHP
  2. $ S_fname = "93e.php" ;
  3. $ O_fname = "93e.htm" ;
  4. Ob_end_clean ();
  5. Ob_start ();
  6. Include ($s _fname);
  7. $ length = Ob_get_length ();
  8. $ Buffer = ob_get_contents ();
  9. $ Buffer = Eregi_replace ("R", "", $buffer);
  10. Ob_end_clean ();
  11. $ FP = fopen ($o _fname, "w+");
  12. Fwrite ($fp, $buffer);
  13. Fclose ($FP);
  14. ?>


 
 
  1. < ? PHP
  2. $ S_fname = "93e.php" ;
  3. $ O_fname = "93e.htm" ;
  4. Ob_end_clean (); Ob_start ();
  5. Include ($s _fname);
  6. $ length = Ob_get_length ();
  7. $ Buffer = ob_get_contents ();
  8. $ Buffer = Eregi_replace ("R", "", $buffer);
    Ob_end_clean ();
  9. $ FP = fopen ($o _fname, "w+");
    Fwrite ($fp, $buffer); Fclose ($FP);
  10. ?>

This allows the 93e.php to be converted to a static HTML file, note that the file to be converted cannot have, Ob_end_clean (), and Ob_start (), and that the directory has write permissions.

The above is the PHP generation HTML file implementation method introduced, only for everyone to reference the study.


http://www.bkjia.com/PHPjc/446221.html www.bkjia.com true http://www.bkjia.com/PHPjc/446221.html techarticle learn PHP generated HTML file 1, below use a method of template!? php $ fp = fopen (templets.html,a); if ($fp) {$ fup = fread ($fp, FileSize (templets.html) ); $ fp2 = fopen (html.shtml ...

  • 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.