In PHP, ob_end_clean() erases the contents of the active output buffer and turns that top buffer off.
Nothing from that buffer is sent. The nesting level from ob_get_level() goes down by one. Use it when you captured output only to discard it, or when an inner buffer should disappear without printing.
Syntax
Call ob_end_clean() with the values you need. Start with this line.
PHP
$ok = ob_end_clean();
Call
What it does
ob_end_clean()
Clears and ends the active buffer; returns true on success.
ob_start(); echo "x"; ob_end_clean();
Discards "x" and turns buffering off.
ob_get_level()
Drops by one after a successful ob_end_clean().
With nested buffers, only the top (innermost) buffer is ended. Outer buffers stay active. With no active buffer, the call fails and returns false.
Library declarations
PHP
ob_end_clean(): bool
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
bool
true on success, false on failure.
PHP Examples
Example 1 — Discard Buffered Output
Buffer a message, end-clean it, then print a short status. The buffered message never appears.