<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
    2 => 'ファイル全体を読み込んで配列に格納する',
  ),
  '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' => 'ja',
    '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">ファイル全体を読み込んで配列に格納する</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">
   ファイル全体を配列に読み込みます。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    ファイルの内容を文字列として返すには <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span>
    を使用します。
   </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">
       ファイルへのパス。
      </p>
      <div class="tip"><strong class="tip">ヒント</strong><p class="simpara"><a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> が有効の場合、この関数のファイル名として
URL を使用することができます。ファイル名の指定方法に関する詳細は
<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">
       オプションのパラメータ <code class="parameter">flags</code>
       は、以下の定数のうちのひとつ、あるいは複数の組み合わせとなります。
       <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">
           <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">
           配列の各要素の最後の改行を省略します。
          </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">
           空行を読み飛ばします。
          </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">
           デフォルトのストリームコンテキストを使いません。
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para"><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">
   ファイルを配列に入れて返します。
   配列の各要素はファイルの各行に対応します。改行記号はついたままとなります。
   失敗すると <span class="function"><strong>file()</strong></span> は <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">
    <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong> を指定しない限り、
    配列に取り込まれた各行は行末文字も含みます。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">
マッキントッシュコンピュータ上で作成されたファイルを読み込む際に、
<code class="literal">PHP</code> が行末を認識できないという問題が発生した場合、
実行時の設定オプション<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">
   PHP 8.3.0 以降では、<code class="parameter">flags</code> に不正な値、
   たとえば <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong> のような値が含まれていた場合、
   <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> がスローされます。
  </p>
  <p class="para">
   ファイルが存在しない場合は <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> レベルのエラーが発生します。
  </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>
       <code class="parameter">flags</code> に不正な値が含まれている場合、
       <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> がスローされるようになりました。
      </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> の例</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">// ファイルの内容を配列に取り込みます。<br />// この例ではHTTPを通してURL上のHTMLソースを取得します。<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">// 配列をループしてHTMLをHTMLソースとして表示し、行番号もつけます。<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">// オプションのパラメータを使う<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">IIS のような、いくつかの標準に
対応してない Web サーバーは、PHP に警告を発生させるような手順でデータを送信します。
このようなサーバーを使用する場合は、<a href="errorfunc.configuration.php#ini.error-reporting" class="link">
error_reporting</a> を警告を発生しないレベルまで小さくする必要があります。
PHP では、<code class="literal">https://</code> ラッパーでストリームをオープンする際に
バグがある IIS サーバーソフトウエアを検出することができ、この警告を抑制することができます。
あなたが <code class="literal">ssl://</code> ソケットを作成するために  <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> を使用している場合、
自らこの警告を検出し、抑制する必要があります。</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> - ファイルを出力する</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - ファイルまたは URL をオープンする</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - インターネット接続もしくは Unix ドメインソケット接続をオープンする</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - プロセスへのファイルポインタをオープンする</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); ?>