Load the contents of a file into a string.
<?php echo file_get_contents(“test.txt”); ?> |
The file_get_contents() function reads the entire content of a file into a string.
This function is the preferred method for reading file contents into a string. It may use memory mapping techniques, if supported by the server, to improve performance.
file_get_contents(path, include_path, context, start, max_length) |
Parameter |
Description |
path |
Mandatory. Specifies the path to the file to be read. |
include_path |
Optional. Set this parameter to |
context |
Optional. Specifies the context for the file handle. A context is a set of options that can alter stream behavior. This can be omitted by using |
start |
Optional. Specifies the position in the file to start reading from. Negative values count backward from the end of the file. |
max_length |
Optional. Specifies the maximum length of data to read. The default is to read until the end of the file (EOF). |
Return Value: |
Returns the entire file as a string, or |
PHP Version: |
4.3+ |
Binary Safe: |
Yes, in PHP 4.3 |
PHP Changelog: |
PHP 7.1 introduced support for negative values in the |