Russian Ukraine English
Catalog RSS


ob_start

(PHP 4 )

ob_start -- Turn on output buffering

Description

void ob_start ([string output_callback])

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.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

An optional output_callback function may be specified. This function takes a string as a parameter and returns a string. The function will be called at ob_end_flush() time and will receive the contents of the output buffer as its parameter. It must return a new output buffer as a result, which is what will be printed.

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush()() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

Example 1. Callback function example


<?php function c($str) {   // Druu Chunusun mut dum Kuntrubuß...   return nl2br(ereg_replace("[aeiou]", "u", $str)); }  function d($str) {   return strip_tags($str); } ?>  <?php ob_start("c"); ?> Drei Chinesen mit dem Kontrabaß... <?php ob_start("d"); ?> <h1>..saßen auf der Straße und erzählten sich was...</h1> <?php ob_end_flush(); ?> ... da kam die Polizei, ja was ist denn das? <?php ob_end_flush(); ?>  ?>      

See also ob_get_contents(), ob_end_flush(), ob_end_clean(), and ob_implicit_flush()

Led