file
Read the entire file into an array
file() function reads the entire file into an array.
Similar tofile_get_contents() , the difference is file() returns the file as an array. Each unit in the array is a corresponding line in the file, including line breaks.
If it fails, false is returned.
<?php
print_r(file("test.txt"));
?>
输出:
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? )
file ( path , include_path , context )
| parameter | describe |
|---|---|
| path | Required. Specifies the file to be read. |
| include_path | Optional. If you also want to search for files in include_path, you can set this parameter to "1". |
| context | Optional. Specifies the environment for file handles. context is a set of options that can modify the behavior of a stream. If null is used, it will be ignored. |
Support for context is added by PHP 5.0.0.
Each row in the returned array includes a line ending character, so if the line ending character is not needed, you also need to use rtrim() function.