Home  >  Article  >  Backend Development  >  What does fgets mean in php

What does fgets mean in php

青灯夜游
青灯夜游Original
2021-12-30 18:29:224066browse

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