PHP - Function fgets()
Advertisements
Syntax
string fgets ( resource $handle [, int $length] );
Definition and Usage
It gets a line from file pointer.
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
handle The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()). |
2 |
length Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. |
Return Value
It returns a string of up to length - 1 bytes read from the file pointed to by handle. If an error occurs, returns FALSE.
Example
Following is the usage of this function −
<?php $handle = @fopen("/plublic/sample.txt", "w"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 512); echo $buffer; } fclose($handle); } ?>
php_function_reference.htm
Advertisements