reference/filesystem/functions/file.xml
89b506b5b654f9eac45d9fc65bfe78ad89254c2b
89b506b5b654f9eac45d9fc65bfe78ad89254c2b
...
...
@@ -9,10 +9,10 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>array</type><methodname>file</methodname>
12
+
<type class="union"><type>array</type><type>false</type></type><methodname>file</methodname>
13
13
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
14
14
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
15
-
<methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam>
15
+
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>context</parameter><initializer>&null;</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Reads an entire file into an array.
...
...
@@ -62,7 +62,7 @@
62
62
</term>
63
63
<listitem>
64
64
<simpara>
65
-
Omit newline at the end of each array element
65
+
Omit newline at the end of each array element.
66
66
</simpara>
67
67
</listitem>
68
68
</varlistentry>
...
...
@@ -72,7 +72,17 @@
72
72
</term>
73
73
<listitem>
74
74
<simpara>
75
-
Skip empty lines
75
+
Skip empty lines.
76
+
</simpara>
77
+
</listitem>
78
+
</varlistentry>
79
+
<varlistentry>
80
+
<term>
81
+
<constant>FILE_NO_DEFAULT_CONTEXT</constant>
82
+
</term>
83
+
<listitem>
84
+
<simpara>
85
+
Don't use the default context.
76
86
</simpara>
77
87
</listitem>
78
88
</varlistentry>
...
...
@@ -83,13 +93,7 @@
83
93
<varlistentry>
84
94
<term><parameter>context</parameter></term>
85
95
<listitem>
86
-
<para>
87
-
A context resource created with the
88
-
<function>stream_context_create</function> function.
89
-
</para>
90
-
<para>
91
96
¬e.context-support;
92
-
</para>
93
97
</listitem>
94
98
</varlistentry>
95
99
</variablelist>
...
...
@@ -114,12 +118,40 @@
114
118
115
119
<refsect1 role="errors">
116
120
&reftitle.errors;
121
+
<simpara>
122
+
As of PHP 8.3.0, throws a <exceptionname>ValueError</exceptionname>
123
+
if <parameter>flags</parameter> includes any invalid values, such
124
+
as <constant>FILE_APPEND</constant>.
125
+
</simpara>
117
126
<para>
118
127
Emits an <constant>E_WARNING</constant> level error if the file
119
128
does not exist.
120
129
</para>
121
130
</refsect1>
122
131
132
+
<refsect1 role="changelog">
133
+
&reftitle.changelog;
134
+
<informaltable>
135
+
<tgroup cols="2">
136
+
<thead>
137
+
<row>
138
+
<entry>&Version;</entry>
139
+
<entry>&Description;</entry>
140
+
</row>
141
+
</thead>
142
+
<tbody>
143
+
<row>
144
+
<entry>8.3.0</entry>
145
+
<entry>
146
+
<exceptionname>ValueError</exceptionname> is thrown for any
147
+
invalid values of <parameter>flags</parameter>.
148
+
</entry>
149
+
</row>
150
+
</tbody>
151
+
</tgroup>
152
+
</informaltable>
153
+
</refsect1>
154
+
123
155
<refsect1 role="examples">
124
156
&reftitle.examples;
125
157
<para>
...
...
@@ -137,10 +169,7 @@ foreach ($lines as $line_num => $line) {
137
169
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
138
170
}
139
171
140
-
// Another example, let's get a web page into a string. See also file_get_contents().
141
-
$html = implode('', file('http://www.example.com/'));
142
-
143
-
// Using the optional flags parameter since PHP 5
172
+
// Using the optional flags parameter
144
173
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
145
174
?>
146
175
]]>
...
...
@@ -158,11 +187,11 @@ $trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
158
187
&reftitle.seealso;
159
188
<para>
160
189
<simplelist>
190
+
<member><function>file_get_contents</function></member>
161
191
<member><function>readfile</function></member>
162
192
<member><function>fopen</function></member>
163
193
<member><function>fsockopen</function></member>
164
194
<member><function>popen</function></member>
165
-
<member><function>file_get_contents</function></member>
166
195
<member><function>include</function></member>
167
196
<member><function>stream_context_create</function></member>
168
197
</simplelist>
169
198