PHP file_get_contents () function
Definition and Usage
file_get_contents () reads the entire file into a string.
This function is used to read the contents of the file into a string in the preferred method. If the server operating system support, will use memory mapping techniques to enhance performance.
grammar
file_get_contents(path,include_path,context,start,max_length)
参数 | 描述 |
---|---|
path | 必需。规定要读取的文件。 |
include_path | 可选。如果您还想在 include_path(在 php.ini 中)中搜索文件的话,请设置该参数为 '1'。 |
context | 可选。规定文件句柄的环境。context 是一套可以修改流的行为的选项。若使用 NULL,则忽略。 |
start | 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 中新增的。 |
max_length | 可选。规定读取的字节数。该参数是 PHP 5.1 中新增的。 |
Tips and Notes
Tip: This function is binary safe.(Meaning that the binary data (such as images) and character data can use this function to write.)
Examples
<?php
echo file_get_contents("test.txt");
?>
echo file_get_contents("test.txt");
?>
The code above will output:
This is a test file with test text.
Complete PHP Filesystem Reference Manual