Home  >  Article  >  Backend Development  >  php fgets function_PHP tutorial

php fgets function_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:08872browse

php fgets function ​

fgets
(PHP 4, PHP 5)

fgets - Get line pointer from file

Description
String fgets(resource$handle[summary$length])
Get line pointer from file.

Parameters

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()).

Length
Read when end length - 1 byte is read, newline (which is included in the return value), or EOF parsing (whichever comes first). If no length is specified, reading of the stream continues until the end of the line is reached.

Note: Prior to PHP 4.3.0, omissions would assume a line length of 1024. If most of the lines in the file are larger than 8KB, it is more efficient for your script to specify a maximum line length.



Return value
Returns a string of length up to - 1 byte read from the file pointed out by processing.

If an error occurs, returns FALSE.

Modify

Release Notes
4.3.0 fgets() is now binary safe
4.2.0 The length parameter is optional

Look at an example:

$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
While (!feof($handle)) {
          $buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445477.htmlTechArticlephp fgets function fgets (PHP 4, PHP 5) fgets - Get the line from the file pointer description string fgets (resource$handle[summary$length]) Get line pointer from file. Parameter handle...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn