Home > Article > Backend Development > What does file mean in php
PHP file() function
Definition and usage (Recommended learning: PHP video tutorial)
file() function Read the entire file into an array.
Similar to file_get_contents(), except that file() returns the file as an array. Each unit in the array is a corresponding line in the file, including newlines.
If failed, return false.
Syntax
file(path,include_path,context)<br/>
Parameter description:
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 a file handle.
context is a set of options that can modify the behavior of the stream. If null is used, it is ignored.
Explanation
Support for context was added in PHP 5.0.0.
Each row in the returned array includes line terminators, so if line terminators are not required, you need to use the rtrim() function.
Tips
Note: Starting from PHP 4.3.0, you can use file_get_contents() to read the file into a string and return it.
Note: As of PHP 4.3.0, file() is safe to use with binary files.
Note: If you encounter that PHP cannot recognize the line ending characters of Macintosh files when reading files, you can activate the auto_detect_line_endings runtime configuration option.
<?php<br/>print_r(file("test.txt"));<br/>?><br/>
Output:
Array<br/>(<br/>[0] => Hello World. Testing testing!<br/>[1] => Another day, another line.<br/>[2] => If the array picks up this line,<br/>[3] => then is it a pickup line?<br/>)<br/>
The above is the detailed content of What does file mean in php. For more information, please follow other related articles on the PHP Chinese website!