fileReads entire file into an arrayDescriptionarrayfilestringfilenameintflagsresourcecontext
Similiar to file_get_contents, except that
file 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;.
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
Prior to PHP 5.0.0 the flags parameter only
covered include_path and was
enabled with 1.
$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/'));
?>
]]>
&tip.fopen-wrapper;
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;
As of PHP 4.3.0 you can use file_get_contents to
return the contents of a file as a string.
In PHP 4.3.0 file became binary safe.
¬e.context-support;
&warn.ssl-non-standard;
See also readfile,
fopen, fsockopen,
popen, file_get_contents,
include, and
stream_context_create