PHP file_get_contents () function

Source: Internet
Author: User
Definition and usage

The 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.

The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance.

Syntax
file_get_contents(path,include_path,context,start,max_length)
Parameters Description
Path Required. Specifies the file to be read.
Include_path Optional. If you want to search for files in include_path, you can set this parameter to "1 ".
Context

Optional. Specifies the file handle environment.

Context is a set of options that can modify the behavior of a stream. If null is used, this parameter is ignored.

Start Optional. Specifies the location where the file starts reading. This parameter is newly added in PHP 5.1.
Max_length Optional. The number of bytes to read. This parameter is newly added in PHP 5.1.
Description

PairContextThe supported parameters are added in PHP 5.0.0.

Tips and comments

Note: this function can be safely used for binary objects.

Example
<?phpecho file_get_contents("test.txt");?>

Output:

This is a test file with test text.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.