PHP file() 函數
定義和用法
file() 函數把整個文件讀入一個數組中。
數組中的每個元素都是文件中相應的一行,包括換行符在內。
語法
file(path,include_path,context)
参数 | 描述 |
---|---|
path | 必需。规定要读取的文件。 |
include_path | 可选。如果您还想在 include_path(在 php.ini 中)中搜索文件的话,请设置该参数为 '1'。 |
context | 可选。规定文件句柄的环境。context 是一套可以修改流的行为的选项。若使用 NULL,则忽略。 |
提示和註釋
提示:從PHP 4.3開始,該函數是二進制安全的。(意思是二進制數據(如圖像)和字符數據都可以使用此函數寫入。)
實例
<?php
print_r(file("test.txt"));
?>
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?
)
(
[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參考手冊