PHP fgets() function
Definisyon at paggamit
Ang fgets() function ay kumukuha ng isang linya mula sa pointer ng file.
Gramata
fgets(from,The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore)
Parametro | Paglalarawan |
---|---|
from | Hinihingi. Tukuyin ang file na dapat basahin. |
The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore | Piliin. Tukuyin ang bilang ng byte na dapat basahin. Ang default ay 1024 byte. |
说明
description from file The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore pointing to the file, read a line and return the length up to The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore - 1-byte string. When encountering a newline character (including in the return value), EOF, or having read The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore- Stop after 1 byte (depending on which one comes first). If not specified
Then it defaults to 1K, or 1024 bytes.
If it fails, it returns false.
From PHP 4.3 onwards, this function can be used safely for binary files. Early versions are not applicable.The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore Tips and Comments The parameter has become optional since PHP 4.2.0. If ignored, the line length is assumed to be 1024 bytes. From PHP 4.3 onwards, ignore length
From PHP 4.3 onwards, this function can be used safely for binary files. Early versions are not applicable.It will continue to read data from the stream until the end of the line. If most of the lines in the file are greater than 8 KB, it is more effective to specify the maximum line length in the script in terms of resource utilization.
From PHP 4.3 onwards, this function can be used safely for binary files. Early versions are not applicable.Note:
If PHP cannot recognize the line ending of Macintosh files when reading files, you can activate the auto_detect_line_endings runtime configuration option.
Instance
<?php $file = fopen("test.txt","r"); Example 1 fclose($file); ?>
Output similar to:
Hello, this is a test file.
Example 2
<?php $file = fopen("test.txt","r"); while(! feof($file)) { echo fgets($file) . "<br />"; } fclose($file); ?>
Output similar to:
Hello, this is a test file. There are three lines here. This is the last line.