Home Tutorial Php Phpfiles The fgets function example in PHP, fgets php, fgets in php

 
 

The fgets function example in PHP, fgets php, fgets in php
Posted on: September 22, 2009 at 12:00 AM
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

 

Related Tags for The fgets function example in PHP, fgets php, fgets in php:


Ask Questions?

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.