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 supported by the server operating system, memory mapping technology is also used to enhance performance.
file_get_contents(path,include_path,context,start,max_length)
parameter | describe |
---|---|
path | Required. Specifies the file to be read. |
include_path | Optional. Set this parameter to '1' if you also want to search for files in include_path (in php.ini). |
context | Optional. Specifies the environment for a 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 begin reading. This parameter is new in PHP 5.1. |
max_length | Optional. Specifies the number of bytes to read. This parameter is new in PHP 5.1. |
Tip: This function is binary safe. (Meaning that both binary data (such as images) and character data can be written using this function.)
<?phpecho file_get_contents("test.txt");?>
The above code will output:
This is a test file with test text.