Home > Backend Development > PHP Tutorial > Examples of ob_get_length buffering and obtaining buffer length in php, phpob_get_length_PHP tutorial

Examples of ob_get_length buffering and obtaining buffer length in php, phpob_get_length_PHP tutorial

WBOY
Release: 2016-07-13 10:13:21
Original
799 people have browsed it

Instances of ob_get_length buffering and obtaining buffer length in php, phpob_get_length

The example in this article describes the method of ob_get_length buffering and obtaining the buffer length in php. Share it with everyone for your reference. The specific method is as follows:

The file_get_contents() function reads the entire file into a string. It is the same as 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 contents of a file into a string. If the operating system supports it, memory mapping technology will also be used to enhance performance.

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

Copy code The code is as follows:
ob_start(); //Open the buffer
echo "hello"; //Output content
$out1= ob_get_contents(); //Get buffer contents
echo "world"; //Output content
$out2=ob_get_contents(); //Get buffer contents again
ob_end_clean(); //Clear the buffer and close
echo $out1; //Output the result obtained for the first time
echo "
";
echo $out2; //Output the result obtained for the second time 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());

Refresh the buffer data, return the data and close the 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());

Get the buffer length, the example code is as follows:

Copy the code The code is as follows:
//Open the buffer
ob_start();
//Output content
echo "hello ";
//Get buffer length
$len1=ob_get_length();
//Output the content
echo "world";
//Get the length of the buffer again
$len2=ob_get_length();
//Clear the buffer and close the buffer
ob_end_clean();
//Output the length obtained for the first time
echo $len1;
echo "
";
//Output the second obtained length to compare the two different results
echo $len2;

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/915443.htmlTechArticleExamples of ob_get_length buffering and obtaining buffer length in php, phpob_get_length This example describes the ob_get_length buffering and obtaining buffer length in php method. Share it with everyone for your reference. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template