Two PHP generated HTML page implementation Code _php tutorial

Source: Internet
Author: User
Tags fread
Two PHP tutorials to generate HTML page implementation code

Open file form with fopen fread fwrite fcolse

$fp = fopen ("templets.html", "a");
if ($fp) {
$fup = Fread ($fp, FileSize ("templets.html"));
$FP 2 = 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 read the file, Fread is used to read the contents of the file opened with fopen, let's take a look at the fread and get instance tutorial.

Definition and usage
The Fread () function reads the file (which can be used safely in binary files).

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

Description
Fread () reads up to length bytes from file pointer files. The function stops reading the file when it has read up to the maximum length of bytes, or when it reaches EOF, or (for a network stream) when a package is available, or when 8,192 bytes have been read (after opening a stream of user space), depending on which situation is encountered first.

$file = fopen ("Test.txt", "R");
Fread ($file, FileSize ("test.txt"));
Fclose ($file);
?>


For more detailed information, please see: http://www.bKjia.c0m/phper/18/753bc9c01fa5a721a81c63887ddccb47.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 (): is to open the buffer, is to put the static file you need to generate the contents of the cache here;
Ob_get_contents (): is to read out the contents of the buffer, the following code for example;
Ob_end_clean (): This is more important, only after using this function, the contents of the buffer will be read out

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

http://www.bkjia.com/PHPjc/631729.html www.bkjia.com true http://www.bkjia.com/PHPjc/631729.html techarticle two PHP tutorials generate HTML page implementation code using fopen fread fwrite fcolse open file form? 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.