Reading data from a file is a common feature of file handling. In PHP, there are various functions that facilitates different ways and features of reading data from a file, including: reading all file data at a single go, reading the file data line by line and even to read the file data character by character.

PHP Read File functions are:

PHP fread()

PHP fgets()

PHP fgetc()

PHP fread() function:

To read a file in PHP, fread() function is used.

Syntax:

string fread (resource $filename , int $filesize )

Filename:This parameter represents the name of the file to read.

Filesize:This parameter represents maximum length of byte to read.

PHP fgets() function:

To read a single line of a file in PHP, fgets() function is used.

Syntax:

string fgets ( resource $filename [, int $filesize ] )

PHP fgetc() function:To read a single character from a file in PHP, fgetsc() function is used.