- File specifies the filename to read content 2. Length Optional parameter specifies the number of bytes to read from the file.
Syntax
PHP fgets() function uses the following syntax.
Example – Read a single line
Below are two examples of a reading single line from a file. Use this example to read the complete first-line content from a file.
Instead of a line, you can also define the number of bytes to read from a file:
Example – Read All Lines
Use this example to read all lines from files one by one using for loop. Use PHP feof() function to find the end of the file.