This article mainly introduces the methods for getting the buffer length and ob_get_length in php. The example analyzes the usage and related skills of the buffer output, which has some reference value. For more information, see
This article mainly introduces the methods for getting the buffer length and ob_get_length in php. The example analyzes the usage and related skills of the buffer output, which has some reference value. For more information, see
This article describes how to buffer and obtain the buffer length of ob_get_length in php. Share it with you for your reference. The specific method is as follows:
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 the operating system supports this function, the memory ing technology is used to improve the performance.
Syntax: file_get_contents (path, include_path, context, start, max_length)
The Code is as follows:
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"
";
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 the file: file_put_contents('buffer.txt ', $ buffer );
List the output header information: print_r (ob_list_handlers ());
Obtain the buffer length. The instance code is as follows:
The Code is as follows:
// 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"
";
// Output the length of the second query to compare two different results
Echo $ len2;
I hope this article will help you with PHP programming.