Current Location: Home> Function Categories> file_get_contents

file_get_contents

Read the entire file into a string
Name:file_get_contents
Category:File system
Programming Language:php
One-line Description:Read the file into a string.

Definition and usage

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.

grammar

 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.

illustrate

Support for context parameters is added by PHP 5.0.0.

Similar Functions
  • Synchronize changes to files (including metadata) fsync

    fsync

    Synchronizechangesto
  • Open process file pointer popen

    popen

    Openprocessfilepoint
  • Test whether the file pointer reaches the end of the file feof

    feof

    Testwhetherthefilepo
  • Establish symbolic connection symlink

    symlink

    Establishsymboliccon
  • Output file readfile

    readfile

    Outputfile
  • Change file owner chown

    chown

    Changefileowner
  • Returns the available space on the file system or disk partition disk_free_space

    disk_free_space

    Returnstheavailables
  • Modify all groups of symbolic links lchgrp

    lchgrp

    Modifyallgroupsofsym
Popular Articles