Home > PHP > Function > Filesystem > file()

file()

file - Reads entire file into an array

Syntax

array file (string $filename, int $flags, resource $context)

Arguments

  • filename - Path to the file. Tip A URL can be used as a filename with this function if the fopen wrappershave been enabled. See fopen() for more details on how to specify the filename. See the List of Supported Protocols/Wrappersfor links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
  • 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. Note: Context support was added with PHP 5.0.0. For a description of contexts, refer to Stream Functions.

Description

Reads an entire file into an array.

Version

PHP 4, 5

Return value

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.