downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

SplFileObject::fgetss> <SplFileObject::fgetcsv
[edit] Last updated: Fri, 14 Jun 2013

view this page in

SplFileObject::fgets

(PHP 5 >= 5.1.0)

SplFileObject::fgetsGets line from file

Description

public string SplFileObject::fgets ( void )

Gets a line from the file.

Parameters

This function has no parameters.

Return Values

Returns a string containing the next line from the file, or FALSE on error.

Errors/Exceptions

Throws a RuntimeException if the file cannot be read.

Examples

Example #1 SplFileObject::fgets() example

This example simply outputs the contents of file.txt line-by-line.

<?php
$file 
= new SplFileObject("file.txt");
while (!
$file->eof()) {
    echo 
$file->fgets();
}
?>

See Also



add a note add a note User Contributed Notes SplFileObject::fgets - [1 notes]
up
0
Anonymous
22 days ago
fgets don't skip empty lines if SplFileObject::SKIP_EMPTY is enabled.

Instead use

<?php
 
while (!$file->eof()) {
   
$file->next();
    echo
$file->current();
  }
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites