PHP file_get_contents() 函數(shù)
定義和用法
file_get_contents() 函數(shù)把整個文件讀入一個字符串中。
和 file() 一樣,不同的是 file_get_contents() 把文件讀入一個字符串。
file_get_contents() 函數(shù)是用于將文件的內(nèi)容讀入到一個字符串中的首選方法。如果操作系統(tǒng)支持,還會使用內(nèi)存映射技術來增強性能。
語法
file_get_contents(path,include_path,context,start,max_length)
參數(shù) | 描述 |
---|---|
path | 必需。規(guī)定要讀取的文件。 |
include_path | 可選。如果也想在 include_path 中搜尋文件的話,可以將該參數(shù)設為 "1"。 |
context |
可選。規(guī)定文件句柄的環(huán)境。 context 是一套可以修改流的行為的選項。若使用 null,則忽略。 |
start | 可選。規(guī)定在文件中開始讀取的位置。該參數(shù)是 PHP 5.1 新加的。 |
max_length | 可選。規(guī)定讀取的字節(jié)數(shù)。該參數(shù)是 PHP 5.1 新加的。 |
說明
對 context 參數(shù)的支持是 PHP 5.0.0 添加的。
提示和注釋
注釋:本函數(shù)可安全用于二進制對象。
例子
<?php echo file_get_contents("test.txt"); ?>
輸出:
This is a test file with test text.