In PHP, fgets means "reading a line of data from a file"; the fgets() function can read one line of data at a time from an open file and return data of a specified length. The syntax "fgets( $handle,$length)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP fgets is a programming language developed based on PHP language A function that can read a row of data from a file pointer and return the data.
fgets() function is used to read one line of data at a time from an open file. The syntax format of this function is as follows:
fgets($handle,$length)
The parameter $handle
is to be opened file; parameter $length
is an optional parameter, used to set the length of data to be read. The
function can read a line from the specified file $handle
and return a string with a maximum length of $length
-1 bytes. Stops after encountering a newline character, EOF, or reading $length-1
bytes. If the $length
parameter is omitted, the default read length is 1k (1024 bytes).
Example:
Use the fgets() function to read a line of data from the "test.txt" file
<?php $file = fopen("test.txt","r"); echo fgets($file); fclose($file); ?>
Then the loop statement can also read all the data line by line:
<?php $handle = fopen("test.txt","r"); if ($handle) { while (($info = fgets($handle, 1024)) !== false) { echo $info.'<br>'; } fclose($handle); } ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does fgets mean in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools
