Php ob_get_length buffer and obtain the buffer Length

Source: Internet
Author: User

The file_get_contents () function reads the entire file into a string.

Like file (), the difference is that file_get_contents () reads the file into a string.

The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance.

Syntax
File_get_contents (path, include_path, context, start, max_length)
*/

Ob_start (); // open the buffer
Echo "hello"; // output content
$ Out1 = ob_get_contents (); // obtain the buffer content
Echo "world"; // output content
$ Out2 = ob_get_contents (); // obtain the buffer content again
Ob_end_clean (); // clear the buffer and disable
Echo $ out1; // output the result obtained for the first time
Echo "<br> ";
Echo $ out2; // output the second result to compare

/*

*/

// This code is used when the output buffer is set to enable (output_buffering = on)
// List the output header information
Print_r (ob_list_handlers ());
// Refresh the buffer data, return the data, and disable the buffer.
$ Buffer = ob_get_flush ();
// Write the buffer data to a file
File_put_contents('buffer.txt ', $ buffer );
// List the output header information
Print_r (ob_list_handlers ());

/*
Obtain the buffer Length
*/

// Open the buffer
Ob_start ();
// Output content
Echo "hello ";
// Obtain the buffer Length
$ Len1 = ob_get_length ();
// Output content again
Echo "world ";
// Obtain the buffer length again
$ Len2 = ob_get_length ();
// Clear the buffer and disable the buffer.
Ob_end_clean ();
// Output the length obtained for the first time
Echo $ len1;
Echo "<br> ";
// Output the length of the second query to compare two different results
Echo $ len2;

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.