<?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.parse-ini-file.php',
    1 => 'parse_ini_file',
    2 => 'Legge un file di configurazione',
  ),
  'up' => 
  array (
    0 => 'ref.filesystem.php',
    1 => 'Filesystem Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.move-uploaded-file.php',
    1 => 'move_uploaded_file',
  ),
  'next' => 
  array (
    0 => 'function.parse-ini-string.php',
    1 => 'parse_ini_string',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/filesystem/functions/parse-ini-file.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.parse-ini-file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">parse_ini_file</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">parse_ini_file</span> &mdash; <span class="dc-title">Legge un file di configurazione</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.parse-ini-file-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>parse_ini_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.boolean.php" class="type bool">bool</a></span> <code class="parameter">$process_sections</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$scanner_mode</code><span class="initializer"> = INI_SCANNER_NORMAL</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>parse_ini_file()</strong></span> carica il
   file ini specificato da <code class="parameter">filename</code>,
   e restituisce le impostazioni in esso in un array associativo.
  </p>
  <p class="para">
   La struttura del file ini è la stessa del <var class="filename">php.ini</var>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.parse-ini-file-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Il nome del file ini da processare. Se viene utilizzato un percorso relativo,
       viene valutato rispetto alla directory di lavoro corrente, quindi l&#039;
       <a href="ini.core.php#ini.include-path" class="link">include_path</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">process_sections</code></dt>
     <dd>
      <p class="para">
       Impostando il parametro <code class="parameter">process_sections</code>
       a <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, si ottiene un array multi-dimensionale con
       i nomi delle sezioni e le impostazioni incluse. Per default
       <code class="parameter">process_sections</code> è impostato a <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>      
      </p>
     </dd>
    
    
     <dt><code class="parameter">scanner_mode</code></dt>
     <dd>
      <p class="para">
       Può essere <strong><code><a href="filesystem.constants.php#constant.ini-scanner-normal">INI_SCANNER_NORMAL</a></code></strong> (default) o 
       <strong><code><a href="filesystem.constants.php#constant.ini-scanner-raw">INI_SCANNER_RAW</a></code></strong>. Se viene fornito 
       <strong><code><a href="filesystem.constants.php#constant.ini-scanner-raw">INI_SCANNER_RAW</a></code></strong>, i valori delle opzioni non verranno analizzati.
      </p>
      <p class="para">
    As of PHP 5.6.1 can also be specified as <strong><code><a href="filesystem.constants.php#constant.ini-scanner-typed">INI_SCANNER_TYPED</a></code></strong>.
    In this mode boolean, null and integer types are preserved when possible.
    String values <code class="literal">&quot;true&quot;</code>, <code class="literal">&quot;on&quot;</code> and <code class="literal">&quot;yes&quot;</code>
    are converted to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>. <code class="literal">&quot;false&quot;</code>, <code class="literal">&quot;off&quot;</code>, <code class="literal">&quot;no&quot;</code>
    and <code class="literal">&quot;none&quot;</code> are considered <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. <code class="literal">&quot;null&quot;</code> is converted to <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>
    in typed mode. Also, all numeric strings are converted to integer type if it is possible.
   </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.parse-ini-file-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Le impostazioni vengono restituite come un <span class="type"><a href="language.types.array.php" class="type array">array</a></span> associativo in caso di successo
   e <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.parse-ini-file-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Contenuto di <var class="filename">sample.ini</var></strong></p>
    <div class="example-contents">
<div class="cdata"><pre>
; Questo è un esempio di file di configurazione
; I commenti cominciano con &#039;;&#039;, come in php.ini

[first_section]
one = 1
five = 5
animal = BIRD

[second_section]
path = &quot;/usr/local/bin&quot;
URL = &quot;http://www.example.com/~username&quot;

[third_section]
phpversion[] = &quot;5.0&quot;
phpversion[] = &quot;5.1&quot;
phpversion[] = &quot;5.2&quot;
phpversion[] = &quot;5.3&quot;

urls[svn] = &quot;http://svn.php.net&quot;
urls[git] = &quot;http://git.php.net&quot;
</pre></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Esempio di <span class="function"><strong>parse_ini_file()</strong></span></strong></p>
    <div class="example-contents"><p>
     Le <a href="language.constants.php" class="link">costanti</a> (ma non le &quot;costanti magiche&quot; come <strong><code><a href="language.constants.magic.php#constant.file">__FILE__</a></code></strong>)
     possono anche essere lette
     in un file ini, quindi se si definisce una costante come un valore di file ini prima di
     eseguire <span class="function"><strong>parse_ini_file()</strong></span>, essa verrà integrata nei
     risultati.  Vengono valutati solo i valori ini e il valore deve essere solo la costante. Per esempio:
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">'BIRD'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Dodo bird'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Lettura senza sezioni<br /></span><span style="color: #0000BB">$ini_array </span><span style="color: #007700">= </span><span style="color: #0000BB">parse_ini_file</span><span style="color: #007700">(</span><span style="color: #DD0000">"sample.ini"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ini_array</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Lettura con sezioni<br /></span><span style="color: #0000BB">$ini_array </span><span style="color: #007700">= </span><span style="color: #0000BB">parse_ini_file</span><span style="color: #007700">(</span><span style="color: #DD0000">"sample.ini"</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ini_array</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [one] =&gt; 1
    [five] =&gt; 5
    [animal] =&gt; Dodo bird
    [path] =&gt; /usr/local/bin
    [URL] =&gt; http://www.example.com/~username
    [phpversion] =&gt; Array
        (
            [0] =&gt; 5.0
            [1] =&gt; 5.1
            [2] =&gt; 5.2
            [3] =&gt; 5.3
        )

    [urls] =&gt; Array
        (
            [svn] =&gt; http://svn.php.net
            [git] =&gt; http://git.php.net
        )

)
Array
(
    [first_section] =&gt; Array
        (
            [one] =&gt; 1
            [five] =&gt; 5
            [animal] =&gt; Dodo bird
        )

    [second_section] =&gt; Array
        (
            [path] =&gt; /usr/local/bin
            [URL] =&gt; http://www.example.com/~username
        )

    [third_section] =&gt; Array
        (
            [phpversion] =&gt; Array
                (
                    [0] =&gt; 5.0
                    [1] =&gt; 5.1
                    [2] =&gt; 5.2
                    [3] =&gt; 5.3
                )

            [urls] =&gt; Array
                (
                    [svn] =&gt; http://svn.php.net
                    [git] =&gt; http://git.php.net
                )

        )

)</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Example #3 Leggere un file php.ini con <span class="function"><strong>parse_ini_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">// Una semplice funzione utilizzata per confrontare i risultati di seguito<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">yesno</span><span style="color: #007700">(</span><span style="color: #0000BB">$expression</span><span style="color: #007700">)<br />{<br />    return(</span><span style="color: #0000BB">$expression </span><span style="color: #007700">? </span><span style="color: #DD0000">'Yes' </span><span style="color: #007700">: </span><span style="color: #DD0000">'No'</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// Ottieni il percorso per php.ini usando la funzione<br />// php_ini_loaded_file() disponibile da PHP 5.2.4<br /></span><span style="color: #0000BB">$ini_path </span><span style="color: #007700">= </span><span style="color: #0000BB">php_ini_loaded_file</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Legge il file php.ini<br /></span><span style="color: #0000BB">$ini </span><span style="color: #007700">= </span><span style="color: #0000BB">parse_ini_file</span><span style="color: #007700">(</span><span style="color: #0000BB">$ini_path</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Stampa e confronta i valori, nota che l'uso di get_cfg_var()<br />// darà gli stessi risultati per la lettura ed il caricamento qui<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'(parsed) magic_quotes_gpc = ' </span><span style="color: #007700">. </span><span style="color: #0000BB">yesno</span><span style="color: #007700">(</span><span style="color: #0000BB">$ini</span><span style="color: #007700">[</span><span style="color: #DD0000">'magic_quotes_gpc'</span><span style="color: #007700">]) . </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'(loaded) magic_quotes_gpc = ' </span><span style="color: #007700">. </span><span style="color: #0000BB">yesno</span><span style="color: #007700">(</span><span style="color: #0000BB">get_cfg_var</span><span style="color: #007700">(</span><span style="color: #DD0000">'magic_quotes_gpc'</span><span style="color: #007700">)) . </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">(parsed) magic_quotes_gpc = Yes
(loaded) magic_quotes_gpc = Yes</pre>
</div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>Example #4 interpolazione di valori</strong></p>
    <div class="example-contents"><p>
     Oltre a valutare le costanti, alcuni caratteri hanno un significato speciale in un valore ini.
     Inoltre, le variabili di ambiente e i valori definiti in precedenza possono essere letti utilizzando
     la sintassi <code class="code">${}</code>.
    </p></div>
    <div class="example-contents">
<div class="cdata"><pre>
; | viene utilizzato per l&#039;OR bit a bit
three = 2|3

; &amp; viene utilizzato per l&#039;AND bit a bit
four = 6&amp;5

; ^ viene utilizzato per lo XOR bit a bit
five = 3^6

; ~ viene utilizzato per la negazione bit a bit
negative_two = ~1

; () viene utilizzato per il raggruppamento
seven = (8|7)&amp;(6|5)

; \ viene utilizzato per effettuare l&#039;escape di un valore.
newline_is = &quot;\\n&quot; ; Restituisce la stringa &quot;\n&quot;, non un carattere di nuova riga.
with quotes = &quot;She said \&quot;Exactly my point\&quot;.&quot; ; Restituisce una stringa con virgolette.

path = ${PATH}
also_five = ${five}

</pre></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">(parsed) magic_quotes_gpc = Yes
(loaded) magic_quotes_gpc = Yes</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.parse-ini-file-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Questa funzione non è collegata con il file
    <var class="filename">php.ini</var>. Esso è già elaborato
    al momento in cui gira lo script. Questa funzione può essere utilizzata
    per leggere i file di configurazione propri dell&#039;applicazione.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Se un valore nel file ini contiene caratteri non alfanumerici,
    esso deve essere delimitato dai doppi apici (&quot;).
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    Ci sono parole riservate che non devono essere usate come chiavi per i
    file ini.  Queste includono: <code class="literal">null</code>, <code class="literal">yes</code>,
    <code class="literal">no</code>, <code class="literal">true</code>, <code class="literal">false</code>,
    <code class="literal">on</code>, <code class="literal">off</code>, <code class="literal">none</code>.
    I valori <code class="literal">null</code>, <code class="literal">off</code>, <code class="literal">no</code> e
    <code class="literal">false</code> producono <code class="literal">&quot;&quot;</code>, e i valori
    <code class="literal">on</code>, <code class="literal">yes</code> e <code class="literal">true</code> producono
    <code class="literal">&quot;1&quot;</code>, salvo che non venga usata la modalità <strong><code><a href="filesystem.constants.php#constant.ini-scanner-typed">INI_SCANNER_TYPED</a></code></strong> (a partire da PHP 5.6.1).
    I caratteri <code class="literal">?{}|&amp;~!()^&quot;</code> non devono essere utilizzati da nessuna parte
    nella chiave e hanno un significato speciale nel valore.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Le voci senza segno di uguale vengono ignorate. Ad esempio, &quot;foo&quot;
    viene ignorato mentre &quot;bar =&quot; viene caricato e aggiunto con un valore
    vuoto. Ad esempio, MySQL ha un&#039;impostazione &quot;no-auto-rehash&quot; 
    nel file <var class="filename">my.cnf</var> che non accetta un valore, quindi
    viene ignorato.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    I file ini sono generalmente trattati come testo normale dai server web e quindi forniti ai browser se richiesto.
    Ciò significa che per sicurezza bisogna mantenere i propri file ini fuori dalla propria docroot o riconfigurare il proprio
    server web per non servirli.  La mancata esecuzione di uno di questi può introdurre un rischio per la sicurezza.
   </p>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.parse-ini-file-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.parse-ini-string.php" class="function" rel="rdfs-seeAlso">parse_ini_string()</a> - Parse a configuration string</span></li>
   </ul>
  </p>
 </div>


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