title: Can anyone explain the length parameter to fgets() in PHP?
body: <p>Assume that I have a file named data.txt with the contents &quot;Blah Blah !&quot;.
  So when I use the code below</p>
  <pre><code>$hnd=fopen('data.txt','r');
  echo fgets($hnd,2);
  </code></pre>
  <p>it displays just one character &quot;B&quot; instead of &quot;Bl&quot;. Later I read the <a href="http://php.net/manual/en/function.fgets.php" rel="nofollow noreferrer">manual</a> stating:</p>
  <blockquote>
  <p><strong>length</strong></p>
  <p>Reading ends when <code>length - 1</code> bytes have been read, or a newline (which is included in the return value), or an EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line.</p>
  </blockquote>
  <p>Can anyone explain to me why it is this way? I mean why is it <code>length-1</code> and not <code>length</code>.</p>