PHP fgets() Function

PHP fgets Function


Definition :

In this tutorial, we are going to be studying about the PHP fgets() Function.The PHP fgets() function returns a line from an open file. This built-in PHP function stop returning on a new line at a specified length or EOF, whichever comes first.

Syntax

  fgets(filelength)

Parameter
Parameter Description
file Required. Specifies the open file to return a line from
length Optional. Specifies the number of bytes to read. Reading stops when length-1 bytes have been reached, or when a new line occurs, or on EOF. If no length is specified, it reads until end of the line

 Example 1 : Given below example read one line from the "demo.txt"open file

Output : Hello World!

Example 2 : Read open file, line by line

Output : Hello World!
              This is fgets function