Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP file_get_contents() Function

PHP file_get_contents() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

file_get_contents() reads an entire file into a string.

This function is the preferred way to read the contents of a file into a string. If the server operating system supports it, memory mapping techniques are also used to enhance performance.

Syntax

file_get_contents(path,include_path,context,start,max_length)

Parameters 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 the include_path (in php.ini).
context Optional. Specifies the context of the file handle. A context is a set of options that can modify the behavior of a stream. If NULL is used, it is ignored.
start Optional. Specifies the position in the file at which 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 (meaning both binary data, such as images, and character data can be written with this function).


Example

The code above will output:

This is a test file with test text.


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual