Definition :
The PHP file() function reads a file into an array. Each element of the array corresponds to a line in the file, with the newline character still attached.
file(filename, flag, context)
Parameter | Description |
---|---|
filename | Required. Specifies the path to the file to read |
flag | Optional. Can be one or more of the following constants:
|
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. Can be skipped by using NULL. |
Given below example Read "demo.txt" file into an array:
Output :
Array
(
[0] => This is the demo file
[1] => this id the second line.
[2] => this is the third line.
)