Home > Article > Backend Development > How to use fgets function
php The fgets() function is used to read a line from the file pointer.
php fgets() function Syntax
Function: Read a line from the file pointer.
Syntax:
fgets(file,length)
Parameters:
file Required. Specifies the file to be read.
length Optional. Specifies the number of bytes to read. The default is 1024 bytes.
Description: Read a line from the file pointed to by file and return a string with a length of at most length - 1 byte. Stops on encountering a newline character (included in the return value), EOF, or after length - 1 bytes have been read (whichever occurs first). If length is not specified, it defaults to 1K, or 1024 bytes. On failure, returns false.
php fgets() function example
<?php $file = fopen("./test.txt","r"); echo fgets($file); ?>
This article is an introduction to the PHP fgets function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use fgets function. For more information, please follow other related articles on the PHP Chinese website!