In PHP, the fgets function is used to read a line of a specified file and return the reading result. The function will end reading when it reaches the specified length, encounters a newline character, or reads to the end of the file. It fails. The return result is false, and the syntax is "fgets(file,length)".
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
fgets function in php What is the usage
#fgets() function returns a line from the open file.
fgets() function will stop returning a new line when it reaches the specified length (length - 1), encounters a newline character, or reaches the end of file (EOF) (whichever comes first).
This function returns FALSE if it fails.
The syntax is:
fgets(file,length)
where file is required to specify the file to be read, and length is optional to specify the number of bytes to be read. The default is 1024 bytes.
Examples are as follows:
<?php $file = fopen("test.txt","r"); echo fgets($file); fclose($file); ?>
or
<?php $file = fopen("test.txt","r"); while(! feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?>
If you are interested, you can click on "PHP Video Tutorial" to learn more about PHP knowledge study.
The above is the detailed content of What is the usage of fgets function 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

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
