<HTML ><HEAD ><TITLE >ob_start</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Output Control Functions" HREF="ref.outcontrol.html"><LINK REL="PREVIOUS" TITLE="ob_implicit_flush" HREF="function.ob-implicit-flush.html"><LINK REL="NEXT" TITLE="Object property and method call overloading" HREF="ref.overload.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ob-implicit-flush.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="ref.overload.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.ob-start" ></A >ob_start</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN70273" ></A ><P > (PHP 4 )</P >ob_start -- Turn on output buffering</DIV ><DIV CLASS="refsect1" ><A NAME="AEN70276" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >ob_start</B > ( [string output_callback])<BR ></BR ><P > This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. </P ><P > The contents of this internal buffer may be copied into a string variable using <A HREF="function.ob-get-contents.html" ><B CLASS="function" >ob_get_contents()</B ></A >. To output what is stored in the internal buffer, use <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A >. Alternatively, <A HREF="function.ob-end-clean.html" ><B CLASS="function" >ob_end_clean()</B ></A > will silently discard the buffer contents. </P ><P > An optional <TT CLASS="parameter" ><I >output_callback</I ></TT > function may be specified. This function takes a string as a parameter and should return a string. The function will be called when <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A > is called, or when the output buffer is flushed to the browser at the end of the request. When <TT CLASS="parameter" ><I >output_callback</I ></TT > is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > In PHP 4.0.4, <A HREF="function.ob-gzhandler.html" ><B CLASS="function" >ob_gzhandler()</B ></A > was introduced to facilitate sending gz-encoded data to web browsers that support compressed web pages. <A HREF="function.ob-gzhandler.html" ><B CLASS="function" >ob_gzhandler()</B ></A > determines what type of content encoding the browser will accept and will return it's output accordingly. </P ></BLOCKQUOTE ></DIV ><P > Output buffers are stackable, that is, you may call <B CLASS="function" >ob_start()</B > while another <B CLASS="function" >ob_start()</B > is active. Just make sure that you call <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A > the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order. </P ><P > <A HREF="function.ob-end-clean.html" ><B CLASS="function" >ob_end_clean()</B ></A >, <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A >, <A HREF="function.ob-clean.html" ><B CLASS="function" >ob_clean()</B ></A >, <A HREF="function.ob-flush.html" ><B CLASS="function" >ob_flush()</B ></A > and <B CLASS="function" >ob_start()</B > may not be called from a callback function. If you call them from callback function, the behavior is undefined. If you would like to delete the contents of a buffer, return "" (a null string) from callback function. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN70307" ></A ><P ><B >Example 1. User defined callback function example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function callback($buffer) { // replace all the apples with oranges return (ereg_replace("apples", "oranges", $buffer)); } ob_start("callback"); ?> <html> <body> <p>It's like comparing apples to oranges. </body> </html> <?php ob_end_flush(); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > Would produce: <DIV CLASS="informalexample" ><A NAME="AEN70311" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><html> <body> <p>It's like comparing oranges to oranges. </body> </html></PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > See also <A HREF="function.ob-get-contents.html" ><B CLASS="function" >ob_get_contents()</B ></A >, <A HREF="function.ob-end-flush.html" ><B CLASS="function" >ob_end_flush()</B ></A >, <A HREF="function.ob-end-clean.html" ><B CLASS="function" >ob_end_clean()</B ></A >, <A HREF="function.ob-implicit-flush.html" ><B CLASS="function" >ob_implicit_flush()</B ></A > and <A HREF="function.ob-gzhandler.html" ><B CLASS="function" >ob_gzhandler()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ob-implicit-flush.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="ref.overload.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ob_implicit_flush</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.outcontrol.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Object property and method call overloading</TD ></TR ></TABLE ></DIV ></BODY ></HTML >