PHP file()Function


PHP Filesystem 参考手册Complete PHP Filesystem Reference

Definition and Usage

The file() function reads the entire file into an array.

Each element in the array is a corresponding line of the file, including newline characters.

Syntax

file(path,include_path,context)

Parameter Description
path Required. Specifies the file to read.
include_path Optional. Set this parameter to '1' if you also want to search for the file in the include_path (in php.ini).
context Optional. Specifies the environment of the file handle. context is a set of options that can modify the behavior of the stream. If NULL is used, it is ignored.


Tips and Notes

Tip:Since PHP 4.3, this function is binary-safe. (This means that binary data (such as images) and character data can both be written using this function.)


Examples

<?php
print_r(file("test.txt"));
?>

The code above 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?
)


PHP Filesystem 参考手册Complete PHP Filesystem Reference Other Extensions