Explanation and example usage of fgets () function in php
This article mainly explains "the explanation and example usage of the fgets () function in php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the explanation and example usage of the fgets () function in php".
Description
1. The fgets () function is used to read one line at a time from the file.
2. It reads until it encounters a newline character (\ n) or EOF. The maximum length to be read is the specified length minus 1 byte.
Syntax:
String fgets (resource $handle [, int $length])
Parameters:
Handle: the file pointer must be valid and must point to a file successfully opened by fopen () or fsockopen () (which has not been closed by fclose ()).
Length: reads a line from the file pointed to by handle and returns a string up to length-1 bytes in length. Encounter a newline character (included in the return value), EOF, or stop after reading the length-1 byte (see which case occurs first). If no length is specified, the default is 1K, or 1024 bytes.
Example:
Create a test.txt file with the following contents:
Autumn is already very late, it seems that it may fall at any time, let winter to replace.
The roaring north wind may be the messenger of winter, coming in a hurry, not wanting to stay in the land for a while, then to the south.
At this point, I believe you have a deeper understanding of the "explanation and example usage of the fgets () function in php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!