Learn
PHP generates HTML file 1, below using a method of template!
- < ? PHP
- $ FP = fopen ("templets.html", "a");
- if ($fp) {
- $ fup = fread ($FP, FileSize
("templets.html"));
- $ FP2 = 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!");
- }
- }
- ?>
- < ? PHP
- $ FP = fopen ("templets.html", "a");
- if ($FP)
- {$fup = fread ($fp, FileSize ("templets.html"));
- $ FP2 = 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!");
- }
- }
- ?>
Simply write the template into a file and save as Html.html
PHP generates HTML files 2, generates HTML file names by time
- < ? PHP
- $ 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> ";
- $ Date Date = Date (' Ymdhis ');
- $ 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.
- 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.
- 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.
- Die ("Write template Success");
- }
- else {
- Fclose ($FP);
- Die ("Write template failed!");
- }
- Echo ($content);
- ?>
- < ? 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
- < font color= #ff0000 > Month day .html</font> " ;
- $ Date Date = Date (' Ymdhis ');
- $ 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.
- if (fwrite ($FP, $content))
- {//format is. int fwrite (int fp (filename),
String string (contents), int [length] (long));
- 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);
- The function is used 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); ?>
PHP generates HTML file 3, below is a way to convert the file name
- < ? PHP
- $ 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);
- ?>
- < ? PHP
- $ 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);
- ?>
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 ...