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.
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 '需要清除的内容'; ob_clean(); ob_end_flush(); echo 'new text...';//新内容 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!