<?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.file.php',
    1 => 'file',
    2 => 'Reads entire file into an array',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Функції Файлової Системи',
  ),
  'prev' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'next' => 
  array (
    0 => 'function.file-exists.php',
    1 => 'file_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filesystem/functions/file.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">file</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">file</span> &mdash; <span class="dc-title">Reads entire file into an array</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.file-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>file</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></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"> = 0</span></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.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$context</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.array.php" class="type array">array</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 an entire file into an array.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    You can use <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span> to return the contents
    of a file as a string.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.file-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Path to the file.
      </p>
      <div class="tip"><strong class="tip">Підказка</strong><p class="simpara">URL як назву файлу можна
використовувати з цією функцією, якщо ввімкнені <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">обгортки fopen</a>. Докладніше про те, як
вказати назву файлу: <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>. На сторінці <a href="wrappers.php" class="xref">Підтримувані протоколи та обгортки</a> є посилання на інформацію про можливості різних обгорток,
примітки щодо їхнього використання, інформацію про будь-які попередньо визначені
цими обгортками змінні.</p></div>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       The optional parameter <code class="parameter">flags</code> can be one, or
       more, of the following constants:
       <dl>
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-use-include-path">FILE_USE_INCLUDE_PATH</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Search for the file in the <a href="ini.core.php#ini.include-path" class="link">include_path</a>.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Omit newline at the end of each array element.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-skip-empty-lines">FILE_SKIP_EMPTY_LINES</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Skip empty lines.
          </span>
         </dd>
        
        
         <dt>
          <strong><code><a href="filesystem.constants.php#constant.file-no-default-context">FILE_NO_DEFAULT_CONTEXT</a></code></strong>
         </dt>
         <dd>
          <span class="simpara">
           Don&#039;t use the default context.
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
       <p class="para"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>
<a href="stream.contexts.php" class="link">контекст потоку</a>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.file-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the file in an array. Each element of the array corresponds to a
   line in the file, with the newline still attached. Upon failure,
   <span class="function"><strong>file()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    Each line in the resulting array will include the line ending, unless
    <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong> is used.
   </p>
  </p></blockquote>
  <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>
 </div>


 <div class="refsect1 errors" id="refsect1-function.file-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="simpara">
   As of PHP 8.3.0, throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>
   if <code class="parameter">flags</code> includes any invalid values, such
   as <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong>.
  </p>
  <p class="para">
   Emits an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> level error if the file
   does not exist.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.file-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> is thrown for any
       invalid values of <code class="parameter">flags</code>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.file-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>file()</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 a file into an array.  In this example we'll go through HTTP to get<br />// the HTML source of a URL.<br /></span><span style="color: #0000BB">$lines </span><span style="color: #007700">= </span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Loop through our array, show HTML source as HTML source; and line numbers too.<br /></span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$lines </span><span style="color: #007700">as </span><span style="color: #0000BB">$line_num </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$line</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Line #&lt;b&gt;</span><span style="color: #007700">{</span><span style="color: #0000BB">$line_num</span><span style="color: #007700">}</span><span style="color: #DD0000">&lt;/b&gt; : " </span><span style="color: #007700">. </span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$line</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;br /&gt;\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Using the optional flags parameter<br /></span><span style="color: #0000BB">$trimmed </span><span style="color: #007700">= </span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">'somefile.txt'</span><span style="color: #007700">, </span><span style="color: #0000BB">FILE_IGNORE_NEW_LINES </span><span style="color: #007700">| </span><span style="color: #0000BB">FILE_SKIP_EMPTY_LINES</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-function.file-notes">
  <h3 class="title">Примітки</h3>
  <div class="warning"><strong class="warning">Увага</strong><p class="para">Якщо використовувати SSL,
Microsoft IIS порушуватиме протокол, закриваючи зʼєднання без надсилання
індикатора <code class="literal">close_notify</code>. Коли буде досягнуто кінця даних, PHP
повідомлятиме: &quot;SSL: Fatal Protocol Error&quot;. Щоб обійти це, значення <a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a> має бути знижене до рівня,
який не включає попереджень. PHP може виявити несправне програмне забезпечення
сервера IIS та приховати попередження, якщо відкривати потік за допомогою
обгортки <code class="literal">https://</code>. Якщо розробник використовує
<span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> для створення сокета <code class="literal">ssl://</code>,
то він сам має виявляти та приховувати це попередження.</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.file-get-contents.php" class="function" rel="rdfs-seeAlso">file_get_contents()</a> - Читає вміст файла в рядку</span></li>
    <li><span class="function"><a href="function.readfile.php" class="function" rel="rdfs-seeAlso">readfile()</a> - Outputs a file</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.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.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - Opens process file pointer</span></li>
    <li><span class="function"><a href="function.include.php" class="function" rel="rdfs-seeAlso">include</a> - include</span></li>
    <li><span class="function"><a href="function.stream-context-create.php" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - Створює контекст потока</span></li>
   </ul>
  </p>
 </div>


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