Current Location: Home> Function Categories> ob_start

ob_start

Turn on output buffering
Name:ob_start
Category:Output buffer control
Programming Language:php
One-line Description:Create a new output buffer and add it to the top of the stack.

Definition and usage

ob_start() function creates an output buffer. A callback function can be passed in to process the content of the buffer and operate on it before it is refreshed. Flags can also be used to allow or limit what the buffer can do.

Example

Create an output buffer:

 <?php
ob_start ( ) ;
echo "This content will not be sent to the browser." ;
ob_end_clean ( ) ;

echo "This content will be sent to the browser." ;
?>

Try it yourself

grammar

 ob_start ( callback , chunk_size , flags ) ;
parameter describe
callback

Elective. A callback function for processing content before the buffer content is flushed.

The callback function should have the following parameters:

parameter describe
Buffer The contents of the output buffer.
phase

A bitmask that may contain any of the following flags:

  • PHP_OUTPUT_HANDLER_START - if the output buffer has just been created
  • PHP_OUTPUT_HANDLER_FLUSH - If the output buffer is currently being refreshed
  • PHP_OUTPUT_HANDLER_FINAL - If the output buffer will be deleted immediately after this operation
chunk_size Elective. The default is 0. When set to a value greater than zero, the buffer will automatically refresh once the content length exceeds this value.
flags

Elective. The default is PHP_OUTPUT_HANDLER_STDFLAGS.

A bitmask that determines what operations the buffer is allowed to perform. It can contain the following flags:

  • PHP_OUTPUT_HANDLER_CLEANABLE - Allows calls to ob_clean(), ob_end_clean() and ob_get_clean().
  • PHP_OUTPUT_HANDLER_FLUSHABLE - Allows calls to ob_flush(), ob_end_flush() and ob_get_flush().
  • PHP_OUTPUT_HANDLER_REMOVABLE - Allows calls to ob_end_clean(), ob_end_flush() and ob_get_flush().
  • PHP_OUTPUT_HANDLER_STDFLAGS - Equivalent to a combination of all the above flags.
  • PHP_OUTPUT_HANDLER_CLEANABLE|
  • PHP_OUTPUT_HANDLER_FLUSHABLE|
  • PHP_OUTPUT_HANDLER_REMOVABLE
Similar Functions
Popular Articles