The fgets function example in PHP, fgets php, fgets in php

This PHP tutorial guide provides example and explains the fgets() function with the help of code.

 
 

Share on Google+Share on Google+

The fgets function example in PHP, fgets php, fgets in php

Ads

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

 

Advertisements

Posted on: September 22, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles