Example of ob_get_length buffer function usage in PHP

Source: Internet
Author: User
File_get_contents The () function reads the entire file into a string, and, like file (), file_get_contents () reads the file into a string.

The file_get_contents () function is the preferred method for reading the contents of a file into a string, and memory-mapping techniques are used to enhance performance if supported by the operating system.

Syntax: file_get_contents (path,include_path,context,start,max_length)

Ob_start ();          Open buffer echo "Hello";         Output content $out 1= ob_get_contents ();      Get buffer contents echo "World";         Output content $out 2=ob_get_contents ();       Get the buffer content again Ob_end_clean ();        Clear the buffer and close echo $out 1;         Output the results for the first time echo "<br>"; echo $out 2;         Outputs the second obtained results to compare

This code is used when output buffering is set to ON (Output_buffering=on)

List Output header information: Print_r (Ob_list_handlers ());

Flush buffer data, return data and close buffer: $buffer =ob_get_flush ();

Write buffer data to file: File_put_contents (' Buffer.txt ', $buffer);

List Output header information: Print_r (Ob_list_handlers ());

To get the buffer length, the instance code is as follows:

Open buffer Ob_start (); The output echo "Hello"; Gets the buffer length $len 1=ob_get_length (); Then output the content echo "World"; Gets the length of the buffer again $len 2=ob_get_length (); Empties the buffer and closes the buffer Ob_end_clean (); Output the length of the first acquisition echo $len 1; echo "<br>"; Outputs the length of the second fetch to compare two different results echo $len 2;
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.