PHP file() Function
Complete PHP Filesystem Reference Manual
Definition and Usage
The file() function reads an entire file into an array.
Each element of the array is a corresponding line from the file, including the newline character.
Syntax
file(path,include_path,context)
| Parameters | Description |
|---|---|
| path | Required. Specifies the file to read. |
| include_path | Optional. Set this parameter to '1' if you also want to search for the file in the include_path (in php.ini). |
| context | Optional. Specifies the context of the file handle. A context is a set of options that can modify the behavior of a stream. If NULL is used, it is ignored. |
Tips and Notes
**Tip:** Since PHP 4.3, this function is binary-safe (meaning both binary data, such as images, and character data can be written with this function).
Example
The code above will output:
Array
(
[0] => Hello World. Testing testing!
[1] => Another day, another line.
[2] => If the array picks up this line,
[3] => then is it a pickup line?
)
Complete PHP Filesystem Reference Manual