Home  >  Article  >  Backend Development  >  How to use fgets function

How to use fgets function

藏色散人
藏色散人Original
2019-02-16 11:10:3420904browse

php The fgets() function is used to read a line from the file pointer.

How to use fgets function

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!

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