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

 
 

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

 

Advertisement

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


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 22, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com