<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.outcontrol.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.ob-start.php',
    1 => 'ob_start',
    2 => 'Turn on output buffering',
  ),
  'up' => 
  array (
    0 => 'ref.outcontrol.php',
    1 => 'Функції Контроля Виводу',
  ),
  'prev' => 
  array (
    0 => 'function.ob-list-handlers.php',
    1 => 'ob_list_handlers',
  ),
  'next' => 
  array (
    0 => 'function.output-add-rewrite-var.php',
    1 => 'output_add_rewrite_var',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/outcontrol/functions/ob-start.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.ob-start" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ob_start</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ob_start</span> &mdash; <span class="dc-title">Turn on output buffering</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.ob-start-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ob_start</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span></span> <code class="parameter">$callback</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$chunk_size</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = <strong><code><a href="outcontrol.constants.php#constant.php-output-handler-stdflags">PHP_OUTPUT_HANDLER_STDFLAGS</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   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 <a href="outcontrol.what-output-is-buffered.php" class="xref">What Output Is Buffered?</a>
   on exactly what output is affected.
  </p>
  <p class="para">
   Output buffers are stackable, that is,
   <span class="function"><strong>ob_start()</strong></span> 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 <a href="outcontrol.nesting-output-buffers.php" class="xref">Nesting Output Buffers</a> for more details.
  </p>
  <p class="para">
   See <a href="outcontrol.user-level-output-buffers.php" class="xref">User-Level Output Buffers</a>
   for a detailed description of output buffers.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ob-start-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">callback</code></dt>
     <dd>
      <p class="para">
       An optional <code class="parameter">callback</code> <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span> may be
       specified. It can also be bypassed by passing <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
      </p>
      <p class="para">
       <code class="parameter">callback</code> is invoked when the output buffer is
       flushed (sent), cleaned, or when the output buffer is flushed
       at the end of the script.
      </p>
      <p class="para">
       The signature of the <code class="parameter">callback</code> is as follows:
      </p>
      <p class="para">
       <div class="methodsynopsis dc-description">
        <span class="methodname"><span class="replaceable">handler</span></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$buffer</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$phase</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

       <dl>
        
         <dt><code class="parameter">buffer</code></dt>
         <dd>
          <span class="simpara">
           Contents of the output buffer.
          </span>
         </dd>
        
        
         <dt><code class="parameter">phase</code></dt>
         <dd>
          <span class="simpara">
           Bitmask of
           <a href="outcontrol.constants.php#constant.php-output-handler-start" class="link">
            <strong><code><a href="outcontrol.constants.php#constant.php-output-handler-start">PHP_OUTPUT_HANDLER_<span class="replaceable">*</span></a></code></strong>
            constants
           </a>.
           See <a href="outcontrol.flags-passed-to-output-handlers.php" class="xref">Flags Passed To Output Handlers</a>
           for more details.
          </span>
         </dd>
        
       </dl>
      </p>
      <p class="para">
       If <code class="parameter">callback</code> returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
       the contents of the buffer are returned.
       See <a href="outcontrol.output-handler-return-values.php" class="xref">Output Handler Return Values</a>
       for more details.
      </p>
      <div class="warning"><strong class="warning">Увага</strong>
       <p class="simpara">
        Calling any of the following functions from within an output handler
        will result in a fatal error:
        <span class="function"><a href="function.ob-clean.php" class="function">ob_clean()</a></span>, <span class="function"><a href="function.ob-end-clean.php" class="function">ob_end_clean()</a></span>,
        <span class="function"><a href="function.ob-end-flush.php" class="function">ob_end_flush()</a></span>, <span class="function"><a href="function.ob-flush.php" class="function">ob_flush()</a></span>,
        <span class="function"><a href="function.ob-get-clean.php" class="function">ob_get_clean()</a></span>, <span class="function"><a href="function.ob-get-flush.php" class="function">ob_get_flush()</a></span>,
        <span class="function"><strong>ob_start()</strong></span>.
       </p>
      </div>
      <p class="para">
       See <a href="outcontrol.output-handlers.php" class="xref">Output Handlers</a>
       and <a href="outcontrol.working-with-output-handlers.php" class="xref">Working With Output Handlers</a>
       for more details on <code class="parameter">callback</code>s (output handlers).
      </p>
     </dd>
    
    
     <dt><code class="parameter">chunk_size</code></dt>
     <dd>
      <p class="para">
       If the optional parameter <code class="parameter">chunk_size</code> is passed,
       the buffer will be flushed after any block of code resulting in output
       that causes the buffer&#039;s length to equal
       or exceed <code class="parameter">chunk_size</code>.
       The default value <code class="literal">0</code> means
       that all output is buffered until the buffer is turned off.
       See <a href="outcontrol.buffer-size.php" class="xref">Buffer Size</a> for more details.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       The <code class="parameter">flags</code> 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
       <a href="outcontrol.constants.php#outcontrol.constants.buffer-control-flags" class="link">
        buffer control flags
       </a>.
       See <a href="outcontrol.operations-on-buffers.php" class="xref">Operations Allowed On Buffers</a>
       for more details.
      </p>
      <p class="para">
       Each flag controls access to a set of functions, as described below:
       <table class="doctable informaltable">
        
         <thead>
          <tr>
           <th>Constant</th>
           <th>Functions</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="outcontrol.constants.php#constant.php-output-handler-cleanable">PHP_OUTPUT_HANDLER_CLEANABLE</a></code></strong></td>
           <td>
            <span class="function"><a href="function.ob-clean.php" class="function">ob_clean()</a></span>
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="outcontrol.constants.php#constant.php-output-handler-flushable">PHP_OUTPUT_HANDLER_FLUSHABLE</a></code></strong></td>
           <td>
            <span class="function"><a href="function.ob-flush.php" class="function">ob_flush()</a></span>
           </td>
          </tr>

          <tr>
           <td><strong><code><a href="outcontrol.constants.php#constant.php-output-handler-removable">PHP_OUTPUT_HANDLER_REMOVABLE</a></code></strong></td>
           <td>
            <span class="function"><a href="function.ob-end-clean.php" class="function">ob_end_clean()</a></span>,
            <span class="function"><a href="function.ob-end-flush.php" class="function">ob_end_flush()</a></span>,
            <span class="function"><a href="function.ob-get-clean.php" class="function">ob_get_clean()</a></span>,
            <span class="function"><a href="function.ob-get-flush.php" class="function">ob_get_flush()</a></span>
           </td>
          </tr>

         </tbody>
        
       </table>

       <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
        <span class="simpara">
         Prior to PHP 8.4.0, the flags parameter could set
         the <a href="outcontrol.constants.php#outcontrol.constants.flags-returned-by-handler" class="link">output handler status flags</a> as well.
        </span>
       </p></blockquote>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ob-start-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Повертає <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> у разі успіху або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ob-start-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 User defined callback function example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$buffer</span><span style="color: #007700">)<br />{<br />  </span><span style="color: #FF8000">// replace all the apples with oranges<br />  </span><span style="color: #007700">return (</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">"apples"</span><span style="color: #007700">, </span><span style="color: #DD0000">"oranges"</span><span style="color: #007700">, </span><span style="color: #0000BB">$buffer</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">ob_start</span><span style="color: #007700">(</span><span style="color: #DD0000">"callback"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;<br /></span>&lt;html&gt;<br />&lt;body&gt;<br />&lt;p&gt;It's like comparing apples to oranges.&lt;/p&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br /><span style="color: #0000BB">&lt;?php<br /><br />ob_end_flush</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">&lt;html&gt;
&lt;body&gt;
&lt;p&gt;It&#039;s like comparing oranges to oranges.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   <div class="example" id="function.ob-start.flags-bc">
    <p><strong>Приклад #2 Creating an unerasable output buffer</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />ob_start</span><span style="color: #007700">(</span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_OUTPUT_HANDLER_STDFLAGS </span><span style="color: #007700">^ </span><span style="color: #0000BB">PHP_OUTPUT_HANDLER_REMOVABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ob-start-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.ob-get-contents.php" class="function" rel="rdfs-seeAlso">ob_get_contents()</a> - Return the contents of the output buffer</span></li>
    <li><span class="function"><a href="function.ob-end-clean.php" class="function" rel="rdfs-seeAlso">ob_end_clean()</a> - Clean (erase) the contents of the active output buffer and turn it off</span></li>
    <li><span class="function"><a href="function.ob-end-flush.php" class="function" rel="rdfs-seeAlso">ob_end_flush()</a> - Flush (send) the return value of the active output handler
   and turn the active output buffer off</span></li>
    <li><span class="function"><a href="function.ob-implicit-flush.php" class="function" rel="rdfs-seeAlso">ob_implicit_flush()</a> - Turn implicit flush on/off</span></li>
    <li><span class="function"><a href="function.ob-gzhandler.php" class="function" rel="rdfs-seeAlso">ob_gzhandler()</a> - ob_start callback function to gzip output buffer</span></li>
    <li><span class="function"><a href="function.ob-iconv-handler.php" class="function" rel="rdfs-seeAlso">ob_iconv_handler()</a> - Convert character encoding as output buffer handler</span></li>
    <li><span class="function"><a href="function.mb-output-handler.php" class="function" rel="rdfs-seeAlso">mb_output_handler()</a> - Callback function converts character encoding in output buffer</span></li>
    <li><span class="function"><a href="function.ob-tidyhandler.php" class="function" rel="rdfs-seeAlso">ob_tidyhandler()</a> - ob_start callback function to repair the buffer</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>