Current Location: Home> Function Categories> fgets

fgets

Read a line from a file pointer
Name:fgets
Category:File system
Programming Language:php
One-line Description:Return a line from the opened file.

Definition and usage

The fgets() function reads a line from a file pointer.

实例

例子 1

<?php

$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);

?>

输出类似:

Hello, this is a test file.

例子 2

<?php

$file = fopen("test.txt","r");

while(! feof($file))
  {
  echo fgets($file). "<br />";
  }

fclose($file);
?>

输出类似:

Hello, this is a test file. 
There are three lines here. 
This is the last line.

grammar

 fgets ( file , length )
parameter describe
file Required. Specifies the file to be read.
length Optional. Specifies the number of bytes to be read. The default is 1024 bytes.

illustrate

Read a line from the file pointed to by the file and return a string of length up to length - 1 byte. It encounters a newline character (including in the return value), EOF, or stops after length - 1 byte has been read (it depends on which case it encounters first). If length is not specified, the default is 1K, or 1024 bytes.

If it fails, return false.

Similar Functions
  • Close an open file pointer fclose

    fclose

    Closeanopenfilepoint
  • Determine whether the given file name is a normal file is_file

    is_file

    Determinewhethertheg
  • Read a line from a file pointer and filter out HTML tags fgetss

    fgetss

    Readalinefromafilepo
  • Determine whether the file exists and is readable is_readable

    is_readable

    Determinewhetherthef
  • Read a line from a file pointer fgets

    fgets

    Readalinefromafilepo
  • Find file paths that match patterns glob

    glob

    Findfilepathsthatmat
  • Check if the file or directory exists file_exists

    file_exists

    Checkifthefileordire
  • Provide information about the document stat

    stat

    Provideinformationab
Popular Articles