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?
)
