The file() function reads the entire file into an array.
Each element in the array is a corresponding line in the file, including newlines.
file(path,include_path,context)
parameter | describe |
---|---|
path | Required. Specifies the file to be read. |
include_path | Optional. Set this parameter to '1' if you also want to search for files in include_path (in php.ini). |
context | Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream. If NULL is used, it is ignored. |
Tip: As of PHP 4.3, this function is binary safe. (Meaning that both binary data (such as images) and character data can be written using this function.)
<?phpprint_r(file("test.txt"));?>
The above code 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?)