fileReads entire file into an array
&reftitle.description;
arrayfilestringfilenameintflags0resourcecontext
Reads an entire file into an array.
You can use file_get_contents to return the contents
of a file as a string.
&reftitle.parameters;
filename
Path to the file.
&tip.fopen-wrapper;
flags
The optional parameter flags can be one, or
more, of the following constants:
FILE_USE_INCLUDE_PATH
Search for the file in the include_path.
FILE_IGNORE_NEW_LINES
Do not add newline at the end of each array element
FILE_SKIP_EMPTY_LINES
Skip empty lines
context
A context resource created with the
stream_context_create function.
¬e.context-support;
&reftitle.returnvalues;
Returns the file in an array. Each element of the array corresponds to a
line in the file, with the newline still attached. Upon failure,
file returns &false;.
Each line in the resulting array will include the line ending, unless
FILE_IGNORE_NEW_LINES is used, so you still need to
use rtrim if you do not want the line ending
present.
¬e.line-endings;
&reftitle.changelog;
&Version;&Description;5.0.0
The context parameter was added
5.0.0
Prior to PHP 5.0.0 the flags parameter only
covered include_path and was
enabled with 1
4.3.0file became binary safe
&reftitle.examples;
file example
$line) {
echo "Line #{$line_num} : " . htmlspecialchars($line) . " \n";
}
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('http://www.example.com/'));
// Using the optional flags parameter since PHP 5
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
]]>
&reftitle.notes;
&warn.ssl-non-standard;
&reftitle.seealso;
readfilefopenfsockopenpopenfile_get_contentsincludestream_context_create