Read one line from the open file:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
Run Example »
The fgets() function returns a line from an open file.
fgets(
file,
length)
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 |
Return Value: | A single line read from the file on success, FALSE on EOF or error |
---|---|
PHP Version: | 4.0+ |
Binary Safe: | Yes, in PHP 4.3 |
Read open file, line by line:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
Run Example »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!