Home  >  Article  >  Backend Development  >  Detailed explanation of usage examples of ob_get_length buffer function in PHP

Detailed explanation of usage examples of ob_get_length buffer function in PHP

伊谢尔伦
伊谢尔伦Original
2017-06-24 14:48:231664browse

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)

ob_start();          //打开缓冲区 
echo "hello";         //输出内容 
$out1= ob_get_contents();      //获得缓冲区内容 
echo "world";         //输出内容 
$out2=ob_get_contents();       //再次获得缓冲区内容 
ob_end_clean();        //清空缓冲区,并关闭 
echo $out1;         //输出第一次获得的结果 
echo "<br>"; 
echo $out2;         //输出第二次获得的结果,以比较

This code is used when the output buffering is set to on (output_buffering=on)

List the output header information: print_r(ob_list_handlers());

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

Get the buffer length, example code As follows:

//打开缓冲区 
ob_start(); 
//输出内容 
echo "hello "; 
//获取缓冲区长度 
$len1=ob_get_length(); 
//再输出内容 
echo "world"; 
//再次获取缓冲区的长度 
$len2=ob_get_length(); 
//清空缓冲区,并关闭缓冲 
ob_end_clean(); 
//输出第一次获取的长度 
echo $len1; 
echo "<br>"; 
//输出第二次获取的长度以比较两次不同的结果 
echo $len2;


The above is the detailed content of Detailed explanation of usage examples of ob_get_length buffer function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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