Load a file into an array, with each line as an element.
<?php print_r(file(“test.txt”)); ?> |
The file() function reads a file into an array, where each element represents a line from the file, including the newline character.
file(filename, flag, context) |
Parameter |
Description |
filename |
Mandatory. Specifies the path to the file to be read. |
flag |
Optional. Can include one or more of the following constants: · FILE_USE_INCLUDE_PATH – Search for the file in the include path specified in php.ini. · FILE_IGNORE_NEW_LINES – Omit the newline character at the end of each array element. · FILE_SKIP_EMPTY_LINES – Skip empty lines in the file. Optional. Specifies the context for the file handle. A context is a set of options that can modify stream behavior. This can be omitted by using NULL. |
context |
Optional. Specifies the context for the file handle. A context is a set of options that can alter stream behavior. This parameter can be omitted by using |
Return Value: |
Returns the entire file as an array, or FALSE on failure. |
PHP Version: |
4.0+ |
Binary Safe: |
Yes, in PHP 4.3 |