<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.splfileobject.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'splfileobject.fread.php',
    1 => 'SplFileObject::fread',
    2 => 'Read from file',
  ),
  'up' => 
  array (
    0 => 'class.splfileobject.php',
    1 => 'SplFileObject',
  ),
  'prev' => 
  array (
    0 => 'splfileobject.fputcsv.php',
    1 => 'SplFileObject::fputcsv',
  ),
  'next' => 
  array (
    0 => 'splfileobject.fscanf.php',
    1 => 'SplFileObject::fscanf',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/spl/splfileobject/fread.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="splfileobject.fread" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SplFileObject::fread</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.11, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SplFileObject::fread</span> &mdash; <span class="dc-title">Read from file</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-splfileobject.fread-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SplFileObject::fread</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$length</code></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">
   Reads the given number of bytes from the file.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-splfileobject.fread-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">length</code></dt>
    <dd>
     <p class="para">
      The number of bytes to read.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-splfileobject.fread-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the string read from the file  or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-splfileobject.fread-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="splfileobject.fread.examples.basic">
    <p><strong>Example #1 <span class="methodname"><strong>SplFileObject::fread()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Get contents of a file into a string<br /></span><span style="color: #0000BB">$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">"/usr/local/something.txt"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$file </span><span style="color: #007700">= new </span><span style="color: #0000BB">SplFileObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$contents </span><span style="color: #007700">= </span><span style="color: #0000BB">$file</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSize</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-splfileobject.fread-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Note that <span class="methodname"><strong>SplFileObject::fread()</strong></span> reads from the current
    position of the file pointer. Use <span class="methodname"><a href="splfileobject.ftell.php" class="methodname">SplFileObject::ftell()</a></span>
    to find the current position of the pointer and <span class="methodname"><a href="splfileobject.rewind.php" class="methodname">SplFileObject::rewind()</a></span>
    (or <span class="methodname"><a href="splfileobject.fseek.php" class="methodname">SplFileObject::fseek()</a></span>) to rewind the pointer position.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-splfileobject.fread-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fread.php" class="function" rel="rdfs-seeAlso">fread()</a> - Binary-safe file read</span></li>
   </ul>
  </p>
 </div>


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