Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Therefore, these functions allow you to avoid errors created by sending headers after
content.


ob_start()


The ob_start function begins output buffering. All text sent by print and similar
functions is saved in a buffer. It will not be sent to the browser until ob_end_flush is
called. The buffer will also be flushed when the script ends.


<?
//begin output buffering
ob_start();
?>




ob_start


print("At this point ");
print(strlen(ob_get_contents()));
print("characters are in the buffer.
\n");
?>


//add a test header
header("X-note: COREPHP");

//dump the contents
ob_end_flush();
?>


ob_end_flush()


The ob_end_flush function halts output buffering and sends the contents of the buffer to
the browser.


ob_end_clean()


The ob_end_clean function halts output buffering and eliminates the contents of the
buffer. Nothing is sent to the browser.


string ob_get_contents()


The ob_get_contents function returns the contents of the output buffer.


Files

Free download pdf