This PHP tutorial guide provides example and explains the fgets() function with the help of code.
This PHP tutorial guide provides example and explains the fgets() function with the help of code.
Syntax of fgets() Function using PHP
fgets ( file_handler [,length ] )
It gives a line from file pointer (returned by fopen(), fsockopen())
It is used with feof() function in loops or with length to display the whole contents of the file
It returns FALSE on EOF file or after given length .
Code for fgets() Function in PHP
<?php
$file1=fopen("c:/rose1/ram.txt","r");
$line=fgets($file1);
echo $line;
echo "<br/>";
$line=fgets($file1);
echo $line;
echo "<br/>";
?>
Output
welcome to roseindia
welcome to roseindia
Code
<?php
$file1=fopen("c:/rose1/ram.txt","r");
do
{
$line=fgets($file1);
echo $line;
echo "<br/>";
}
while(!feof($file1))
?>
Output
welcome to roseindia
welcome to roseindia
welcome to roseindia
welcome to roseindia
welcome to roseindia
welcome to roseindia