PHP fgets() Function
Complete PHP Filesystem Reference Manual
Definition and Usage
The fgets() function returns a line from an open file.
fgets() stops returning a new line when it reaches the specified length (length - 1), encounters a newline, or reaches the end of file (EOF), whichever comes first.
Returns FALSE on failure.
Syntax
fgets(file,length)
| Parameters | Description |
|---|---|
| file | Required. Specifies the file to read. |
| length | Optional. Specifies the number of bytes to read. Default is 1024 bytes. |
Example 1
The code above will output:
Hello, this is a test file.
Example 2: Read a file line by line
" ; } fclose ( $file ) ; ?>The code above will output:
Hello, this is a test file.
There are three lines here.
This is the last line.