<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filesystem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.fgets.php',
    1 => 'fgets',
    2 => 'Gets line from file pointer',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Функції Файлової Системи',
  ),
  'prev' => 
  array (
    0 => 'function.fgetcsv.php',
    1 => 'fgetcsv',
  ),
  'next' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/fgets.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.fgets" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fgets</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">fgets</span> &mdash; <span class="dc-title">Gets line from file pointer</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.fgets-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fgets</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="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">
   Gets a line from file pointer.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fgets-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">stream</code></dt>
     <dd>
      <p class="para">Вказівник на файл має бути дійсним
та має вказувати на файл, успішно відкритий функцією
<span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> або <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> (та не закритий
функцією <span class="function"><a href="function.fclose.php" class="function">fclose()</a></span>).</p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       Reading ends when <code class="parameter">length</code> - 1 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>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fgets-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns a string of up to <code class="parameter">length</code> - 1 bytes read from
   the file pointed to by <code class="parameter">stream</code>. If there is no more data 
   to read in the file pointer, then <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
  </p>
  <p class="para">
   If an error occurs, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fgets-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Reading a file line by line</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$fp </span><span style="color: #007700">= @</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/inputfile.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br />    while ((</span><span style="color: #0000BB">$buffer </span><span style="color: #007700">= </span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">4096</span><span style="color: #007700">)) !== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />        echo </span><span style="color: #0000BB">$buffer</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />    }<br /><br />    if (!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)) {<br />        echo </span><span style="color: #DD0000">"Error: unexpected fgets() fail\n"</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</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.fgets-notes">
  <h3 class="title">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <span class="simpara">Якщо виникають проблеми з
розпізнаванням закінчення рядків під час читання чи створення файлів на
компʼютері Macintosh, може допомогти застосування директиви <a href="filesystem.configuration.php#ini.auto-detect-line-endings" class="link">auto_detect_line_endings</a> під час
виконання.</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    People used to the &#039;C&#039; semantics of <span class="function"><strong>fgets()</strong></span>
    should note the difference in how <code class="literal">EOF</code> is returned.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fgets-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.fgetss.php" class="function" rel="rdfs-seeAlso">fgetss()</a> - Gets line from file pointer and strip HTML tags</span></li>
    <li><span class="function"><a href="function.fread.php" class="function" rel="rdfs-seeAlso">fread()</a> - Binary-safe file read</span></li>
    <li><span class="function"><a href="function.fgetc.php" class="function" rel="rdfs-seeAlso">fgetc()</a> - Gets character from file pointer</span></li>
    <li><span class="function"><a href="function.stream-get-line.php" class="function" rel="rdfs-seeAlso">stream_get_line()</a> - Gets line from stream resource up to a given delimiter</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Opens file or URL</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - Opens process file pointer</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Open Internet or Unix domain socket connection</span></li>
    <li><span class="function"><a href="function.stream-set-timeout.php" class="function" rel="rdfs-seeAlso">stream_set_timeout()</a> - Set timeout period on a stream</span></li>
   </ul>
  </p>
 </div>


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