Web | This Site

Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# PHP Function file_get_contents()

## 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

Parameter | Description
--- | ---
filename | Name of the file to read.
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.

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.
offset | The offset where the reading starts.
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;
    ?>

Advertisement

Online Image Processing

Indian Baby Names