file_get_contents
Read the entire file into a string
file_get_contents()
function reads the entire file into a string.
Like file()
, the difference is that file_get_contents()
reads the file into a string.
file_get_contents()
function is the preferred method used to read the contents of a file into a string. If the operating system supports it, memory mapping technology will also be used to enhance performance.
<?php echo file_get_contents("test.txt"); ?>
输出:
This is a test file with test text.
file_get_contents ( path , include_path , context , start , max_length )
parameter | describe |
---|---|
path | Required. Specifies the file to be read. |
include_path | Optional. If you also want to search for files in include_path, you can set this parameter to "1". |
context |
Optional. Specifies the environment for file handles. context is a set of options that can modify the behavior of a stream. If null is used, it will be ignored. |
start | Optional. Specifies the location where reading begins in the file. This parameter is newly added in PHP 5.1. |
max_length | Optional. Specifies the number of bytes to be read. This parameter is newly added in PHP 5.1. |
Support for context parameters is added by PHP 5.0.0.