The article introduces the PHP functions ob_start(), ob_end_clean(), and ob_get_contents(). Friends in need can refer to them.
Usage of the following three functions
ob_get_contents() - Returns the contents of the output buffer
ob_get_contents
(PHP 4, PHP 5)
ob_get_contents — Returns the contents of the output buffer
Description
string ob_get_contents (void)
Just get the contents of the output buffer, but don't clear it.
Return value
This function returns the contents of the output buffer, or FALSE if the output buffer is invalid.
Example
The code is as follows | Copy code | ||||
ob_start(); echo "Hello "; $out1 = ob_get_contents(); echo "World"; ob_end_clean(); var_dump($out1, $out2); The above routine will output: string(6) "Hello " |
ob_flush() - Flush (send) the contents of the output buffer
ob_flush
(PHP 4 >= 4.2.0, PHP 5)
Description
void ob_flush (void)
This function will send the contents of the buffer (if there is content in it). If you want to further process the contents of the buffer, you must call ob_get_contents() before ob_flush(), because the buffer contents will be discarded after calling ob_flush().
This function will not destroy the output buffer, but functions like ob_end_flush() will destroy the buffer.
Return valueNo return value.
ob_clean() - clear (erase) the output buffer
ob_clean
(PHP 4 >= 4.2.0, PHP 5)
ob_clean — clear (erase) the output buffer
Description
This function is used to discard the contents of the output buffer.
This function will not destroy the output buffer, while functions like ob_end_clean() will destroy the output buffer.
Return value
No return value.
ob_end_flush() - flush out (send out) the contents of the output buffer and close the buffer
ob_end_flush — flush out (send out) the contents of the output buffer and close the buffer代码如下 | 复制代码 |
while (@ob_end_flush()); ?> |
The code is as follows | Copy code |
while (@ob_end_flush());<🎜> ?> |
ob_end_clean() - clears (erases) the buffer and closes output buffering
ob_end_clean — clear (erase) the buffer and close output buffering
Description
bool ob_end_clean (void)
This function discards the contents of the top-most output buffer and closes this buffer. If you want to further process the contents of the buffer, you must call ob_get_contents() before ob_end_clean(), because the buffer contents will be discarded when ob_end_clean() is called.
Return value
Returns TRUE on success, or FALSE on failure. The reason for the error is first of all, there is not a functioning buffer at the time of the call, or the buffer cannot be deleted for some reason (maybe for special buffers Word).
Error/Exception
If the function fails, an E_NOTICE exception will be raised.
Update log
Version Description
4.2.0 Added Boolean return value.
Example
The following example shows a way to remove all output buffers:
The code is as follows
|
Copy code
|
||||
Example #1 ob_end_clean() example ob_end_clean(); ?>
| flush() - Flush the output buffer
Then use ob_get_contents to get the buffer data.
http://www.bkjia.com/PHPjc/629067.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629067.htmlTechArticleThe article introduces the php functions ob_start(), ob_end_clean(), and ob_get_contents(). Friends in need can refer to it. . Usage of the following three functions ob_get_contents() - Returns the contents of the output buffer...