Read a single line from the open file.
<?php $file = fopen(“test.txt”,“r”); echo fgets($file); fclose($file); ?> |
The fgets() function returns a line from an open file.
fgets(file, length) |
Parameter |
Description |
file |
Mandatory. Specifies the open file from which to return a line. |
length |
Optional. Specifies the number of bytes to read. Reading stops when |
Return Value: |
Returns a single line read from the file on success, or |
PHP Version: |
4.0+ |
Binary Safe: |
Yes, in PHP 4.3 |
Read the open file one line at a time.
<?php $file = fopen(“test.txt”,“r”); while(! feof($file)) { echo fgets($file). “<br />”; } fclose($file); ?> |