- PHP File provides various functions to read data.
- There are different functions that allow you to read all file data, read data character by character and read data line by line.
- The PHP file available read functions are given below, they are:
-
- fread ()
- fgets ()
- fgetc ()
PHP Read File- fread ()
- PHP fread () function is used to read data of the file and it consists of two arguments, they are file size and file resource.
Sample Code
Output
PHP Read file- fgets ()
- To read single line from the file PHP fgets () function is used.
Sample Code
Output
PHP Read file- fgetc ()
- To read single character from the file PHP fgetc () function is used and use! feof () function inside the while loop to get all data using fgetc () function.