PHP file_get_contents()Function
Complete PHP Filesystem Reference Manual
Definition and Usage
file_get_contents() reads the entire file into a string.
This function is the preferred method for reading the contents of a file into a string. If the server operating system supports it, memory-mapping technology is also used to enhance performance.
Syntax
file_get_contents(path,include_path,context,start,max_length)
| Parameter | Description |
|---|---|
| path | Required. Specifies the file to read. |
| include_path | Optional. Set this parameter to '1' if you also want to search for the file in include_path (in php.ini). |
| context | Optional. Specifies the context of the file handle. context is a set of options that can modify the behavior of the stream. If NULL is used, it is ignored. |
| start | Optional. Specifies the position in the file to start reading. This parameter was added in PHP 5.1. |
| max_length | Optional. Specifies the number of bytes to read. This parameter was added in PHP 5.1. |
Tips and Notes
Tip:This function is binary-safe. (This means binary data (such as images) and character data can both be written using this function.)
Example
<?php
echo file_get_contents("test.txt");
?>
echo file_get_contents("test.txt");
?>
The above code will output:
This is a test file with test text.
Complete PHP Filesystem Reference Manual Other Extensions