<?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 => 'es',
  ),
  'this' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
    2 => 'Lee el fichero y devuelve el resultado en un array',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Funciones del Sistema de Archivos',
  ),
  'prev' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'next' => 
  array (
    0 => 'function.file-exists.php',
    1 => 'file_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    '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">Lee el fichero y devuelve el resultado en un array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.file-description">
  <h3 class="title">Descripción</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">
   Lee el fichero y devuelve el resultado en un array.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Puede utilizarse la función <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span>
    para devolver el contenido de un fichero en un <span class="type"><a href="language.types.string.php" class="type string">string</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.file-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Ruta de acceso al fichero.
      </p>
      <div class="tip"><strong class="tip">Sugerencia</strong><p class="simpara">
 Puede utilizar una URL como nombre de archivo con esta función, si el
 <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">gestor fopen</a> ha sido activado. Véase <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>
 para más detalles sobre cómo especificar el nombre del archivo. Consulte
 <a href="wrappers.php" class="xref">Protocolos y Envolturas soportados</a> para más información sobre las capacidades de los diferentes gestores,
 las notas sobre su uso, así como la información sobre las variables predefinidas que proporcionan.
</p></div>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       El argumento opcional <code class="parameter">flags</code> puede ser
       una o más de las siguientes constantes:
       <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">
           Busca el fichero en el <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">
           No añade nueva línea al final de cada elemento del array.
          </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">
           Ignora las líneas vacías.
          </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">
           No utiliza el contexto por omisión.
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">Un <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de
 <a href="stream.contexts.php" class="link">contexto de flujo</a>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.file-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Devuelve el fichero en un array.
   Cada elemento del array corresponde a una línea del fichero,
   y los retornos de carro se colocan al final de la línea. Si ocurre un error,
   <span class="function"><strong>file()</strong></span> devolverá <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Cada línea del array resultante incluirá un final de línea, a menos
    que se utilice <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">Nota</strong>: <span class="simpara">
 Si PHP no reconoce correctamente los finales de línea al leer archivos que han sido creados o leídos en
 un Macintosh, la activación de la opción de configuración
 <a href="filesystem.configuration.php#ini.auto-detect-line-endings" class="link">auto_detect_line_endings</a> puede resolver el problema.
</span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.file-errors">
  <h3 class="title">Errores/Excepciones</h3>
  <p class="simpara">
   A partir de PHP 8.3.0, se lanza una excepción <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>
   si el <code class="parameter">flags</code> contiene valores inválidos,
   como <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong>.
  </p>
  <p class="para">
   Emite un error de nivel <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> si el fichero
   no existe.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.file-changelog">
  <h3 class="title">Historial de cambios</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versión</th>
      <th>Descripción</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Se lanza una excepción <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> para
       cualquier valor inválido del <code class="parameter">flags</code>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.file-examples">
  <h3 class="title">Ejemplos</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Ejemplo #1 Ejemplo con <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">// Lee una página web en un array.<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">// Muestra todas las líneas del array como código HTML, con los números de línea<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">// Uso de flag<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">Notas</h3>
  <div class="warning"><strong class="warning">Advertencia</strong><p class="para">
 Cuando SSL es utilizado, el servidor IIS de Microsoft violará el protocolo al cerrar la conexión sin
 enviar un indicador <code class="literal">close_notify</code>. PHP lo reportará como &quot;SSL: Fatal Protocol Error&quot;
 cuando se llegue al final de los datos. Para evitar esto, el nivel de la directiva
 <a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a> debe ser bajado para no incluir los avisos.
 PHP puede detectar automáticamente los servidores IIS defectuosos al abrir
 el flujo utilizando <code class="literal">https://</code> y suprimirá el aviso.
 Al utilizar <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> para crear un socket <code class="literal">ssl://</code>,
 es responsabilidad del desarrollador detectar y suprimir el aviso.
</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-seealso">
  <h3 class="title">Ver también</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> - Lee todo un fichero en una cadena</span></li>
    <li><span class="function"><a href="function.readfile.php" class="function" rel="rdfs-seeAlso">readfile()</a> - Muestra un fichero</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Abre un fichero o un URL</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Abre un socket de conexi&oacute;n Internet o Unix</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - Crea un puntero de archivo de proceso</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> - Crea un contexto de flujo</span></li>
   </ul>
  </p>
 </div>


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