|
1 | | -<?xml version="1.0" encoding="UTF-8"?> |
2 | | -<!-- EN-Revision: n/a Maintainer: fernando Status: working --> |
3 | | - <!-- CREDITS: cortesi --> |
4 | | - <refentry xml:id="function.file" xmlns="http://docbook.org/ns/docbook"> |
5 | | - <refnamediv> |
6 | | - <refname>file</refname> |
7 | | - <refpurpose>Legge l'intero file in un vettore</refpurpose> |
8 | | - </refnamediv> |
9 | | - <refsect1> |
10 | | - <title>Descrizione</title> |
11 | | - <methodsynopsis> |
12 | | - <type>array</type><methodname>file</methodname> |
13 | | - <methodparam><type>string</type><parameter>filename</parameter></methodparam> |
14 | | - <methodparam choice="opt"><type>int</type><parameter>use_include_path</parameter></methodparam> |
15 | | - <methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam> |
16 | | - </methodsynopsis> |
17 | | - <para> |
18 | | - Identica a <function>readfile</function>, eccetto per il fatto che |
19 | | - <function>file</function> restituisce il file in un vettore. Ogni |
20 | | - elemento del vettore corrisponde ad una riga del file, con il carattere di |
21 | | - newline ancora inserito. Se la funzione non riesce restituisce |
22 | | - &false;. |
23 | | - </para> |
24 | | - <para> |
25 | | - Puoi impostare il secondo parametro, <parameter>use_include_path</parameter>, (opzionale) ad "1", |
26 | | - se vuoi cercare il file nel <link |
27 | | - linkend="ini.include-path">include_path</link>. |
28 | | - </para> |
29 | | - <para> |
30 | | - <informalexample> |
31 | | - <programlisting role="php"> |
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<!-- EN-Revision: e3ae86b439c1963f0cd6d262712e2d3f7e85bc37 Maintainer: Manuel dG Status: working --> |
| 3 | +<!-- CREDITS: cortesi--> |
| 4 | +<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.file"> |
| 5 | + <refnamediv> |
| 6 | + <refname>file</refname> |
| 7 | + <refpurpose>Legge l'intero file in un array</refpurpose> |
| 8 | + </refnamediv> |
| 9 | + |
| 10 | + <refsect1 role="description"> |
| 11 | + &reftitle.description; |
| 12 | + <methodsynopsis> |
| 13 | + <type class="union"><type>array</type><type>false</type></type><methodname>file</methodname> |
| 14 | + <methodparam><type>string</type><parameter>filename</parameter></methodparam> |
| 15 | + <methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam> |
| 16 | + <methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>context</parameter><initializer>&null;</initializer></methodparam> |
| 17 | + </methodsynopsis> |
| 18 | + <para> |
| 19 | + Legge l'intero file in un array. |
| 20 | + </para> |
| 21 | + <note> |
| 22 | + <para> |
| 23 | + In alternativa puoi usare <function>file_get_contents</function> per estrarre il contenuto |
| 24 | + di un file sottoforma di stringa. |
| 25 | + </para> |
| 26 | + </note> |
| 27 | + </refsect1> |
| 28 | + |
| 29 | + <refsect1 role="parameters"> |
| 30 | + &reftitle.parameters; |
| 31 | + <para> |
| 32 | + <variablelist> |
| 33 | + <varlistentry> |
| 34 | + <term><parameter>filename</parameter></term> |
| 35 | + <listitem> |
| 36 | + <para> |
| 37 | + Percorso del file. |
| 38 | + </para> |
| 39 | + &tip.fopen-wrapper; |
| 40 | + </listitem> |
| 41 | + </varlistentry> |
| 42 | + <varlistentry> |
| 43 | + <term><parameter>flags</parameter></term> |
| 44 | + <listitem> |
| 45 | + <para> |
| 46 | + Il parametro opzionale <parameter>flags</parameter> può essere uno, o |
| 47 | + più valori, delle seguenti costanti: |
| 48 | + <variablelist> |
| 49 | + <varlistentry> |
| 50 | + <term> |
| 51 | + <constant>FILE_USE_INCLUDE_PATH</constant> |
| 52 | + </term> |
| 53 | + <listitem> |
| 54 | + <simpara> |
| 55 | + Cerca il file in <link |
| 56 | + linkend="ini.include-path">include_path</link>. |
| 57 | + </simpara> |
| 58 | + </listitem> |
| 59 | + </varlistentry> |
| 60 | + <varlistentry> |
| 61 | + <term> |
| 62 | + <constant>FILE_IGNORE_NEW_LINES</constant> |
| 63 | + </term> |
| 64 | + <listitem> |
| 65 | + <simpara> |
| 66 | + Ometterà newline alla fine di ogni elemento dell'array |
| 67 | + </simpara> |
| 68 | + </listitem> |
| 69 | + </varlistentry> |
| 70 | + <varlistentry> |
| 71 | + <term> |
| 72 | + <constant>FILE_SKIP_EMPTY_LINES</constant> |
| 73 | + </term> |
| 74 | + <listitem> |
| 75 | + <simpara> |
| 76 | + Salta le righe vuote |
| 77 | + </simpara> |
| 78 | + </listitem> |
| 79 | + </varlistentry> |
| 80 | + <varlistentry> |
| 81 | + <term> |
| 82 | + <constant>FILE_NO_DEFAULT_CONTEXT</constant> |
| 83 | + </term> |
| 84 | + <listitem> |
| 85 | + <simpara> |
| 86 | + Non usa il context di default |
| 87 | + </simpara> |
| 88 | + </listitem> |
| 89 | + </varlistentry> |
| 90 | + </variablelist> |
| 91 | + </para> |
| 92 | + </listitem> |
| 93 | + </varlistentry> |
| 94 | + <varlistentry> |
| 95 | + <term><parameter>context</parameter></term> |
| 96 | + <listitem> |
| 97 | + ¬e.context-support; |
| 98 | + </listitem> |
| 99 | + </varlistentry> |
| 100 | + </variablelist> |
| 101 | + </para> |
| 102 | + </refsect1> |
| 103 | + |
| 104 | + <refsect1 role="returnvalues"> |
| 105 | + &reftitle.returnvalues; |
| 106 | + <para> |
| 107 | + Restituisce il file in un array. Ogni elemento dell'array corrisponde a una |
| 108 | + riga nel file, con newline incluso. In caso di errore, |
| 109 | + <function>file</function> restituisce &false;. |
| 110 | + </para> |
| 111 | + <note> |
| 112 | + <para> |
| 113 | + Per ogni linea riportata nell'array risultante includerà newline, a meno |
| 114 | + che non venga usato <constant>FILE_IGNORE_NEW_LINES</constant>. |
| 115 | + </para> |
| 116 | + </note> |
| 117 | + ¬e.line-endings; |
| 118 | + </refsect1> |
| 119 | + |
| 120 | + <refsect1 role="errors"> |
| 121 | + &reftitle.errors; |
| 122 | + <simpara> |
| 123 | + A partire da PHP 8.3.0, genera un <exceptionname>ValueError</exceptionname> |
| 124 | + se <parameter>flags</parameter> include valori non validi, come |
| 125 | + <constant>FILE_APPEND</constant>. |
| 126 | + </simpara> |
| 127 | + <para> |
| 128 | + Emette un <constant>E_WARNING</constant> a livello d'errore |
| 129 | + se il file non esiste. |
| 130 | + </para> |
| 131 | + </refsect1> |
| 132 | + |
| 133 | + <refsect1 role="changelog"> |
| 134 | + &reftitle.changelog; |
| 135 | + <informaltable> |
| 136 | + <tgroup cols="2"> |
| 137 | + <thead> |
| 138 | + <row> |
| 139 | + <entry>&Version;</entry> |
| 140 | + <entry>&Description;</entry> |
| 141 | + </row> |
| 142 | + </thead> |
| 143 | + <tbody> |
| 144 | + <row> |
| 145 | + <entry>8.3.0</entry> |
| 146 | + <entry> |
| 147 | + <exceptionname>ValueError</exceptionname> viene generato |
| 148 | + per qualunque valore di <parameter>flags</parameter> non valido. |
| 149 | + </entry> |
| 150 | + </row> |
| 151 | + </tbody> |
| 152 | + </tgroup> |
| 153 | + </informaltable> |
| 154 | + </refsect1> |
| 155 | + |
| 156 | + <refsect1 role="examples"> |
| 157 | + &reftitle.examples; |
| 158 | + <para> |
| 159 | + <example> |
| 160 | + <title><function>file</function> esempio</title> |
| 161 | + <programlisting role="php"> |
32 | 162 | <![CDATA[ |
33 | 163 | <?php |
34 | | -// inserisce una pagina web in un array e la stampa. In questo esempio useremo il protocollo |
35 | | -// HTTP per ottenere il sorgente di un URL |
| 164 | +// Get a file into an array. In this example we'll go through HTTP to get |
| 165 | +// the HTML source of a URL. |
36 | 166 | $lines = file('http://www.example.com/'); |
37 | | -// Ciclo attraverso l'array, si visualizzerà il sorgente come html ed i numeri di linea |
38 | | -foreach($lines as $line_num => $line) { |
| 167 | +
|
| 168 | +// Loop through our array, show HTML source as HTML source; and line numbers too. |
| 169 | +foreach ($lines as $line_num => $line) { |
39 | 170 | echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; |
40 | 171 | } |
41 | 172 |
|
42 | | -// Un'altro esempio, inserisce la pagina web in una stringa. Vedere anche file_get_contents(). |
43 | | -$html = implode('', file ('http://www.example.com/')); |
| 173 | +// Using the optional flags parameter |
| 174 | +$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
44 | 175 | ?> |
45 | 176 | ]]> |
46 | | - </programlisting> |
47 | | - </informalexample> |
48 | | - </para> |
49 | | -&tip.fopen-wrapper; |
50 | | - <note> |
51 | | - <para> |
52 | | - Ciascuna riga dell'array restituito conterrà il carattere di fine riga, occorre, pertanto, |
53 | | - utilizzare <function>rtrim</function> se si desidera rimuovere il carattere |
54 | | - di fine riga. |
55 | | - </para> |
56 | | - </note> |
57 | | - ¬e.line-endings; |
58 | | - <note> |
59 | | - <para> |
60 | | - A partire da PHP 4.3.0 si può utilizzare <function>file_get_contents</function> per |
61 | | - memorizzare il contenuto di un file in una stringa in formato binario. |
62 | | - </para> |
63 | | - </note> |
64 | | - ¬e.context-support; |
65 | | - &warn.ssl-non-standard; |
66 | | - <para> |
67 | | - Vedere anche <function>readfile</function>, |
68 | | - <function>fopen</function>, <function>fsockopen</function>, |
69 | | - <function>popen</function>, <function>file_get_contents</function> e |
70 | | - <function>include</function>. |
71 | | - </para> |
72 | | - </refsect1> |
73 | | - </refentry> |
| 177 | + </programlisting> |
| 178 | + </example> |
| 179 | + </para> |
| 180 | + </refsect1> |
| 181 | + |
| 182 | + <refsect1 role="notes"> |
| 183 | + &reftitle.notes; |
| 184 | + &warn.ssl-non-standard; |
| 185 | + </refsect1> |
| 186 | + |
| 187 | + <refsect1 role="seealso"> |
| 188 | + &reftitle.seealso; |
| 189 | + <para> |
| 190 | + <simplelist> |
| 191 | + <member><function>file_get_contents</function></member> |
| 192 | + <member><function>readfile</function></member> |
| 193 | + <member><function>fopen</function></member> |
| 194 | + <member><function>fsockopen</function></member> |
| 195 | + <member><function>popen</function></member> |
| 196 | + <member><function>include</function></member> |
| 197 | + <member><function>stream_context_create</function></member> |
| 198 | + </simplelist> |
| 199 | + </para> |
| 200 | + </refsect1> |
| 201 | + |
| 202 | +</refentry> |
74 | 203 |
|
75 | 204 | <!-- Keep this comment at the end of the file |
76 | 205 | Local variables: |
|
0 commit comments