Definition and usage
The file_get_contents () function reads the entire file into a string.
Like file (), the difference is that file_get_contents () reads the file into a string.
The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance.
Syntax
file_get_contents(path,include_path,context,start,max_length)
| Parameters |
Description |
| Path |
Required. Specifies the file to be read. |
| Include_path |
Optional. If you want to search for files in include_path, you can set this parameter to "1 ". |
| Context |
Optional. Specifies the file handle environment.
Context is a set of options that can modify the behavior of a stream. If null is used, this parameter is ignored. |
| Start |
Optional. Specifies the location where the file starts reading. This parameter is newly added in PHP 5.1. |
| Max_length |
Optional. The number of bytes to read. This parameter is newly added in PHP 5.1. |
Description
PairContextThe supported parameters are added in PHP 5.0.0.
Tips and comments
Note: this function can be safely used for binary objects.
Example
<?phpecho file_get_contents("test.txt");?>
Output:
This is a test file with test text.