ob_start
ob_start
Turn on output buffering
bool **ob_start** $callback int $chunk_size int $flags
This function will turn output buffering on. While output buffering is active no output is sent from the script, instead the output is stored in an internal buffer. See on exactly what output is affected.
Output buffers are stackable, that is,
may be called while another buffer is active.
If multiple output buffers are active,
output is being filtered sequentially
through each of them in nesting order.
See for more details.
ob_start
See for a detailed description of output buffers.
callback
An optional may be
specified. It can also be bypassed by passing null.
callback``callable
is invoked when the output buffer is
flushed (sent), cleaned, or when the output buffer is flushed
at the end of the script.
`callback`
The signature of the is as follows:
`callback`
```php
string **** string $buffer int $phase
`buffer`Contents of the output buffer.
`phase`
Bitmask of
.
See
for more details.
PHP_OUTPUT_HANDLER_*
constants
If returns false
the contents of the buffer are returned.
See
for more details.
`callback`
> **Waarschuwing:** > Calling any of the following functions from within an output handler
> will result in a fatal error:
> , ,
> , ,
> , ,
> .
> `ob_clean``ob_end_clean``ob_end_flush``ob_flush``ob_get_clean``ob_get_flush``ob_start`
See
and
for more details on s (output handlers).
`callback`
`chunk_size`
If the optional parameter is passed,
the buffer will be flushed after any block of code resulting in output
that causes the buffer's length to equal
or exceed .
The default value means
that all output is buffered until the buffer is turned off.
See for more details.
`chunk_size``chunk_size``0`
`flags`
The parameter is a bitmask that controls
the operations that can be performed on the output buffer. The default
is to allow output buffers to be cleaned, flushed and removed, which
can be set explicitly via the
.
See
for more details.
`flags`buffer control flags
Each flag controls access to a set of functions, as described below:
> **Opmerking:** > Prior to PHP 8.4.0, the flags parameter could set
> the as well.
> output handler status flags
return.success
**Voorbeeld: User defined callback function example**
```php
<?php
function callback($buffer)
{
// replace all the apples with oranges
return (str_replace("apples", "oranges", $buffer));
}
ob_start("callback");
?>
<html>
<body>
<p>It's like comparing apples to oranges.</p>
</body>
</html>
<?php
ob_end_flush();
?>
<html>
<body>
<p>It's like comparing oranges to oranges.</p>
</body>
</html>
Voorbeeld: Creating an unerasable output buffer
<?php
ob_start(null, 0, PHP_OUTPUT_HANDLER_STDFLAGS ^ PHP_OUTPUT_HANDLER_REMOVABLE);
?>
ob_get_contents``ob_end_clean``ob_end_flush``ob_implicit_flush``ob_gzhandler``ob_iconv_handler``mb_output_handler``ob_tidyhandler