How to use fgets function

藏色散人
Release: 2023-04-05 09:30:01
Original
20904 people have browsed it

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)
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template