PHP - Function file_get_contents()


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.

Parameters

Sr.No Parameter & Description
1

filename

Name of the file to read.

2

flags

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

3

context

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

4

offset

The offset where the reading starts.

5

maxlen

Maximum 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;
?>

php_function_reference.htm

Advertisements