search
HomeBackend DevelopmentPHP ProblemWhat does fgets mean in php

What does fgets mean in php

Dec 30, 2021 pm 06:29 PM
fgetsphp

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)".

What does fgets mean in php

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

What does fgets mean in php

<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>

What does fgets mean in php

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.&#39;<br>&#39;;
        }
        fclose($handle);
    }  
?>

What does fgets mean in php

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

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

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

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools