Two php methods to generate html page implementation code _ PHP Tutorial

Source: Internet
Author: User
Php generates html page implementation code. Two php tutorials generate html page implementation code using fopenfreadfwritefcolse to open the file form? Php?fpfopen(templets.html,a?*if(?fp=***fupfread($fp,filesize(templets.html two php tutorials generate html page implementation code

Use fopen fread fwrite fcolse to open a file

$ 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 reads files. fread is used to read files opened with fopen. let's take a look at the fread and gets instance tutorials.

Definition and usage
Fread () function reads files (which can be safely used for binary files ).

Syntax
Fread (file, length) parameter description
File is required. Required to read open files.
Length is required. Specifies the maximum number of bytes to read.

Description
Fread () reads a maximum of length bytes from the file pointer. This function can be read by a maximum of length bytes, or when it reaches the eof, or (for network streams) when a package is available, or (after opening the user space stream) when 8192 bytes have been read, the system stops reading files.

$ File = fopen ("test.txt", "r ");
Fread ($ file, filesize ("test.txt "));
Fclose ($ file );
?>


For more details, see: http://www.bKjia. c0m/phper/18/753 bc9c01fa5a721a81c63887ddccb47.htm

Cache output ob_end_clean ob_start ob_get_length ob_get_contents function

$ 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 );
?>


Three functions: "ob_start (), ob_end_clean (), ob_get_contents ()"

Ob_start (): it is used to open the buffer, that is, to cache the content of the static file you need to generate here;
Ob_get_contents (): read the content in the buffer. the following code is used as an example;
Ob_end_clean (): This is important. only when this function is used can the content in the buffer be read.

For more details, see http://www.bKjia. c0m/phper/php-cy/35433.htm

Why does fuse use fopen fread fwrite fcolse to open a file? Php $ fp = fopen (templets.html, a); if ($ fp) {$ fup = fread ($fp,filesize(templets.html...

Related Article

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.