The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. Because it will use memory mapping techniques, if this is supported by the server, to enhance performance.
string file_get_contents ( string $filename [, bool $use_include_path = FALSE [, resource $context [, int $offset = 0 [, int $maxlen ]]]] )
This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE. file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
The above example will output something similar to:
string(14) "lle Bjori Ro"
Parameter | Description |
---|---|
path | Required. Specifies the file to read |
include_path | Optional. Set this parameter to '1' if you want to search for the file in the include_path (in php.ini) as well |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. Can be skipped by using NULL. |
start | Optional. Specifies where in the file to start reading. This parameter was added in PHP 5.1 |
max_length | Optional. Specifies how many bytes to read. This parameter was added in PHP 5.1 |
If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().