Copyright © tutorialspoint.com

PHP Function file_get_contents()

previous
Advertisements

Syntax

string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen]]]] );

Definition and Usage

This function is identical to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes.

Paramters

ParameterDescription
filenameName of the file to read.
flagsThe value of flags can be any combination of the following flags joined with the binary OR (|) operator.
  • FILE_USE_INCLUDE_PATH: Search for filename in the include directory.
  • FILE_TEXT: If unicode semantics are enabled, the default encoding of the read data is UTF-8. his flag cannot be used with FILE_BINARY.
  • FILE_BINARY: With this flag, the file is read in binary mode. This is the default setting and cannot be used with FILE_TEXT.
contextA valid context resource created with stream_context_create(). If you don't need to use a custom context, you can skip this parameter by NULL.
offsetThe offset where the reading starts.
maxlenMaximum length of data read.

Return Value

The function returns the read data or FALSE on failure.

Example

Following is the usage of this function:

<?php
$lines = file_get_contents('http://www.example.com/');

# This will read complete index.htm file.
echo $lines;
?>
previous

Copyright © tutorialspoint.com