Home  >  Article  >  Backend Development  >  How to clear page content in php

How to clear page content in php

王林
王林Original
2020-11-02 14:10:233068browse

php method to clear page content: 1. Use the ob_start function to open the output control buffer; 2. Use the ob_clean function to clear the output buffer; 3. Use the ob_end_flush function to flush out the buffer content and close the buffer.

How to clear page content in php

Function introduction:

ob_clean clears (erases) the output buffer

(Video tutorial recommendation: PHP video tutorial)

ob_clean ( void )

This function is used to discard the contents of the output buffer.

This function does not destroy the output buffer like the ob_end_clean() function.

Output buffering must have been started by ob_start() with the PHP_OUTPUT_HANDLER_CLEANABLE flag. Otherwise ob_clean() will have no effect.

ob_end_flush Flushes out (sends out) the contents of the output buffer and closes the buffer.

This function will send the contents of the top-level buffer (if there is content in it) and close the buffer. If you want to further process the contents of the buffer, you must call ob_get_contents() before ob_end_flush(), because the buffer contents are discarded after calling ob_end_flush().

ob_start opens the output control buffer

This function will open the output buffer. When output buffering is activated, the script will not output content (except http headers), instead the content to be output is stored in an internal buffer.

Clear the content in the PHP page

<?PHP
ob_start();   //ob_start()需要放在需要删除的内容前面
echo &#39;需要清除的内容&#39;;   
ob_clean();
ob_end_flush();
echo &#39;new text...&#39;;//新内容
exit;
?>

Related recommendations: php training

The above is the detailed content of How to clear page content 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