Home Tutorial Php Examples fgets() example


Share on Google+Share on Google+
fgets() example
Posted on: July 30, 2009 at 12:00 AM
This is the example of fgets().

 fgets() function

fgets() function reads the data and returns a line from an open file. It begins to read from beginning and stop returning on a new line or on the specified length whichever comes first. By default it reads the first 1 kilo bytes, but it can be set lesser or larger. If this function is used in one file that has no line breaks, it returns False.  



Parameter Description

File is essential for running this function. The file must also be opened. 

Length is optional. Setting the length at specifies number of bytes will increase or decrease the file compilation. 


$file = fopen("upload.php", "r") or exit("Unable to open file!");

echo fgets($file). "<br />";

In this example, the output will either print the line or return False.


Related Tags for fgets() example:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements