<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'function.stream-get-contents.php',
    1 => 'stream_get_contents',
    2 => 'L&ecirc; o restante de um fluxo em uma string',
  ),
  'up' => 
  array (
    0 => 'ref.stream.php',
    1 => 'Fun&ccedil;&otilde;es de Fluxo',
  ),
  'prev' => 
  array (
    0 => 'function.stream-filter-remove.php',
    1 => 'stream_filter_remove',
  ),
  'next' => 
  array (
    0 => 'function.stream-get-filters.php',
    1 => 'stream_get_filters',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'reference/stream/functions/stream-get-contents.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stream-get-contents" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_get_contents</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_get_contents</span> &mdash; <span class="dc-title">Lê o restante de um fluxo em uma string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-get-contents-description">
  <h3 class="title">Descrição</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_get_contents</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$stream</code></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.integer.php" class="type int">int</a></span></span> <code class="parameter">$length</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">$offset</code><span class="initializer"> = -1</span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Idêntico a <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span>, exceto que
   <span class="function"><strong>stream_get_contents()</strong></span> opera em um recurso de fluxo
   já aberto e retorna o conteúdo remanescente em uma string, até o
   número de bytes definido em <code class="parameter">length</code> e iniciando na posição
   <code class="parameter">offset</code> especificada.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-get-contents-parameters">
  <h3 class="title">Parâmetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">stream</code> (<span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>)</dt>
     <dd>
      <p class="para">
       Um recurso de fluxo (ex.: retornado de <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>)
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code> (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)</dt>
     <dd>
      <p class="para">
       O máximo de bytes para leitura. O padrão é <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> (ler todo o buffer
       remanescente).
      </p>
     </dd>
    
    
     <dt><code class="parameter">offset</code> (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>)</dt>
     <dd>
      <p class="para">
       Posiciona o ponteiro até o deslocamento especificado antes da leitura. Se o número for negativo,
       não irá ocorrer deslocamento e a leitura irá iniciar na posição atual.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-get-contents-returnvalues">
  <h3 class="title">Valor Retornado</h3>
  <p class="para">
   Retorna uma string ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> em caso de falha.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-get-contents-changelog">
  <h3 class="title">Registro de Alterações</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versão</th>
      <th>Descrição</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">length</code> agora pode ser nulo.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-get-contents-examples">
  <h3 class="title">Exemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemplo #1 Exemplo de <span class="function"><strong>stream_get_contents()</strong></span></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">if (</span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">)) {<br />    </span><span style="color: #FF8000">// mostra toda a página iniciando na posição 10<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, -</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br />}<br /><br /><br />if (</span><span style="color: #0000BB">$stream </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.net'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">)) {<br />    </span><span style="color: #FF8000">// mostra os 5 primeiros bytes<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.stream-get-contents-notes">
  <h3 class="title">Notas</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: <span class="simpara">Esta função é
compatível com dados binários.</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Ao especificar um valor de <code class="parameter">length</code> diferente de <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, esta função irá
    imediatamente alocar um buffer interno deste tamanho, mesmo que
    o conteúdo real seja significativamente menor.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-get-contents-seealso">
  <h3 class="title">Veja Também</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fgets.php" class="function" rel="rdfs-seeAlso">fgets()</a> - L&ecirc; uma linha de um ponteiro de arquivo</span></li>
    <li><span class="function"><a href="function.fread.php" class="function" rel="rdfs-seeAlso">fread()</a> - Leitura de arquivo segura para bin&aacute;rio</span></li>
    <li><span class="function"><a href="function.fpassthru.php" class="function" rel="rdfs-seeAlso">fpassthru()</a> - Imprime todos os dados restantes de um ponteiro de arquivo</span></li>
   </ul>
  </p>
 </div>

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