Home > Backend Development > PHP Problem > What does fgets mean in php

What does fgets mean in php

青灯夜游
Release: 2023-03-14 16:58:01
Original
4107 people have browsed it

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

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

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

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!

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