<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
    2 => 'Liest eine komplette Datei in ein Array',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Dateisystem',
  ),
  'prev' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'next' => 
  array (
    0 => 'function.file-exists.php',
    1 => 'file_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    '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">Liest eine komplette Datei in ein Array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.file-description">
  <h3 class="title">Beschreibung</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">
   Liest eine komplette Datei in ein Array.
  </p>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Sie können <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span> benutzen, um den Inhalt
    einer Datei als String zurückgegeben zu bekommen.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.file-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Der Pfad zur Datei.
      </p>
      <div class="tip"><strong class="tip">Tipp</strong><p class="simpara">Wenn
<a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> aktiviert ist, kann
mit dieser Funktion eine URL als Dateiname verwendet werden. Mehr Details dazu,
wie der Dateiname angeben werden muss, sind bei <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> zu
finden. Eine Liste der unterstützten URL-Protokolle, die Fähigkeiten der
verschiedenen Wrapper, Hinweise zu deren Verwendung und Informationen zu den
eventuell vorhandenen vordefinierten Variablen sind unter
<a href="wrappers.php" class="xref">Unterst&uuml;tzte Protokolle und Wrapper</a> zu finden.</p></div>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Der optionale Parameter <code class="parameter">flags</code> kann aus einer
       oder mehreren der folgenden Konstanten bestehen:
       <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">
           Suche nach der Datei im
           <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">
           Entferne den Zeilenumbruch am Ende jedes Array-Elements.
          </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">
           Überspringe leere Zeilen.
          </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">
           Verwende nicht den Standardkontext.
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">Eine <a href="stream.contexts.php" class="link">Stream-Kontext</a>-<span class="type"><a href="language.types.resource.php" class="link">Ressource</a></span>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.file-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt die Datei in einem Array zurück. Jedes Element des Arrays entspricht
   einer Zeile in der Datei, ohne dass der Zeilenumbruch entfernt wird. Im
   Fehlerfall gibt <span class="function"><strong>file()</strong></span> <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurück.
  </p>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Jede Zeile im resultierenden Array enthält den Zeilenumbruch, außer es
    wird <strong><code><a href="filesystem.constants.php#constant.file-ignore-new-lines">FILE_IGNORE_NEW_LINES</a></code></strong> verwendet.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: <span class="simpara">Wenn PHP Zeilenendezeichen
nicht richtig erkennt, entweder beim Lesen von Dateien auf einem Macintosh oder
bei Dateien, die auf einem Macintosh erstellt wurden, kann die Option
<a href="filesystem.configuration.php#ini.auto-detect-line-endings" class="link">auto_detect_line_endings</a>
aktiviert werden.</span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.file-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="simpara">
   Wenn <code class="parameter">flags</code> ungültige Werte enthält, z. B.
   <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong>, wird seit PHP 8.3.0 ein
   <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> ausgelöst.
  </p>
  <p class="para">
   Erzeugt einen Fehler der Stufe <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>, wenn die
   Datei nicht existiert.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.file-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Beschreibung</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Für alle ungültigen Werte von <code class="parameter">flags</code> wird ein
       <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> ausgelöst.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.file-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>file()</strong></span>-Beispiel</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">// Liest eine Datei in ein Array. Hier gehen wir über HTTP, um den<br />// HTML-Quelltext einer URL zu bekommen<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">// Durchgehen des Arrays und Anzeigen des HTML-Quelltexts inkl. Zeilennummern<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">// Benutzung des optionalen Parameters flags<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">Anmerkungen</h3>
  <div class="warning"><strong class="warning">Warnung</strong><p class="para">Bei SSL-Verbindungen zusammen
mit Microsoft IIS hält sich dieser Webserver nicht an das Protokoll und
schließt die Verbindung ohne ein <code class="literal">close_notify</code> zu senden.
PHP quittiert dieses Fehlverhalten mit &quot;SSL: Fatal Protocol Error&quot;, wenn das
Ende der Daten erreicht ist. Eine mögliche Lösung besteht darin, den Level von
<a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a> herabzusetzten und
Warnings auszuschließen. PHP kann fehlerhafte IIS-Serversoftware
erkennen, wenn Sie einen Stream mit dem <code class="literal">https://</code>-Wrapper öffnen,
und unterdrückt die Warnung für Sie. Falls Sie <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span>
benutzen, um einen <code class="literal">ssl://</code>-Socket zu öffnen, müssen Sie selbst
dafür Sorge tragen, die Warnung zu erkennen und diese zu unterdrücken.</p>
</div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-seealso">
  <h3 class="title">Siehe auch</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> - Liest die gesamte Datei in einen String</span></li>
    <li><span class="function"><a href="function.readfile.php" class="function" rel="rdfs-seeAlso">readfile()</a> - Gibt eine Datei aus</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - &Ouml;ffnet eine Datei oder URL</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Stellt eine Internet- oder Unix-Domain-Socket-Verbindung her</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - &Ouml;ffnet einen Dateizeiger f&uuml;r einen Prozess</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> - Creates a stream context</span></li>
   </ul>
  </p>
 </div>


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