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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.