<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.file.php',
    1 => 'file',
    2 => 'Legge l\'intero file in un array',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.fgetss.php',
    1 => 'fgetss',
  ),
  'next' => 
  array (
    0 => 'function.file-exists.php',
    1 => 'file_exists',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    '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">Legge l&#039;intero file in un array</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.file-description">
  <h3 class="title">Descrizione</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">
   Legge l&#039;intero file in un array.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    In alternativa è possibile usare <span class="function"><a href="function.file-get-contents.php" class="function">file_get_contents()</a></span> per estrarre il contenuto
    di un file sotto forma di stringa.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.file-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Percorso del file.
      </p>
      <div class="tip"><strong class="tip">Suggerimento</strong><p class="simpara">È possibile utilizzare una URL come un
nome di file con questa funzione se <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> è stata abilitata.
Vedere <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> per maggiori informazioni su come specificare 
i nomi di file. Vedere <a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a> per i link verso le informazioni
sulle capacità dei vari wrapper, note sul loro uso,
informazioni sulle variabili predefinite che
forniscono.</p></div>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       Il parametro opzionale <code class="parameter">flags</code> può essere uno, o
       più valori, delle seguenti costanti: 
       <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">
           Cerca il file in <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">
           Ometterà newline alla fine di ogni elemento dell&#039;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">
           Salta le righe vuote
          </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">
           Non usa il context di default
          </span>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
       <blockquote class="note"><p><strong class="note">Nota</strong>: <span class="simpara">Il supporto per il contesto è stato
aggiunto in PHP 5.0.0. Per la descrizione del <code class="literal">contesto</code>, fare riferimento a
<a href="ref.stream.php" class="xref">Stream Funzioni</a>.</span></p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.file-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Restituisce il file in un array. Ogni elemento dell&#039;array corrisponde a una
   riga nel file, con newline incluso. In caso di errore,
   <span class="function"><strong>file()</strong></span> restituisce <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">
    Per ogni linea riportata nell&#039;array risultante includerà newline, a meno
    che non venga usato <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">Se PHP non riconosce
correttamente i fine riga durante la lettura di file creati o provenienti
da un computer Macintosh, l&#039;abilitazione dell&#039;opzione di configurazione runtime
<a href="filesystem.configuration.php#ini.auto-detect-line-endings" class="link">auto_detect_line_endings</a>
potrebbe aiutare a risolvere il problema.</span></p></blockquote>
 </div>


 <div class="refsect1 errors" id="refsect1-function.file-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="simpara">
   A partire da PHP 8.3.0, genera un <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>
   se <code class="parameter">flags</code> include valori non validi, come
   <strong><code><a href="filesystem.constants.php#constant.file-append">FILE_APPEND</a></code></strong>.
  </p>
  <p class="para">
   Emette un <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> a livello d&#039;errore
   se il file non esiste.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.file-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</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> viene generato
       per qualunque valore di <code class="parameter">flags</code> non valido.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.file-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Esempio di <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">// inserisce un file in un array e lo stampa. In questo esempio useremo il protocollo<br />// HTTP per ottenere il sorgente HTML di un 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 /></span><span style="color: #FF8000">//Itera attraverso quest'array, mostra il sorgente HTML così com'è e anche i numeri di riga.<br /><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">//Utilizzo del parametro flag opzionale <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">Note</h3>
  <div class="warning"><strong class="warning">Avviso</strong><p class="para">Quando si usa SSL, Microsoft IIS
viola il protocollo chiudendo la connessione senza inviare
un&#039;indicazione <code class="literal">close_notify</code>. PHP indicherà questo con un &quot;SSL: Fatal
Protocol Error&quot; al raggiungimento della fine dei dati. Per aggirare questo problema, occorre
abbassare il livello <a href="errorfunc.configuration.php#ini.error-reporting" class="link">error_reporting</a> per non
includere questi avvisi.
PHP 4.3.7 e successivi sono in grado di identificare gli IIS bacati quando si apre
lo stream utilizzando il wrapper <code class="literal">https://</code> e disabilitano
automaticamente l&#039;avviso. Se si usa <span class="function"><a href="function.fsockopen.php" class="function">fsockopen()</a></span> per creare
un socket <code class="literal">ssl://</code>, occorre identificare e sopprimere
l&#039;avviso manualmente.</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.file-seealso">
  <h3 class="title">Vedere anche:</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> - Legge un file all'interno di una stringa</span></li>
    <li><span class="function"><a href="function.readfile.php" class="function" rel="rdfs-seeAlso">readfile()</a> - Invia un file</span></li>
    <li><span class="function"><a href="function.fopen.php" class="function" rel="rdfs-seeAlso">fopen()</a> - Apre un file o un URL</span></li>
    <li><span class="function"><a href="function.fsockopen.php" class="function" rel="rdfs-seeAlso">fsockopen()</a> - Apre una connessione a un socket appartenente a un dominio Internet o Unix</span></li>
    <li><span class="function"><a href="function.popen.php" class="function" rel="rdfs-seeAlso">popen()</a> - Apre un puntatore ad un file di processo</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); ?>