The SplFileObject::fgets() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is usd to get line from file.
Syntax:
string SplFileObject::fgets( void )
Parameters: This function does not accept any parameter.
Return values: This function returns an string containing the next line from the file return FALSE otherwise.
Below Programs illustrate the SplFileObject::fgets() function in PHP.
Program 1:
<?php // Creating SplFile Object $gfg = new SplFileObject("gfg.txt"); while (!$gfg->eof()) { echo $gfg->fgets(); } ?> |
Output:
GeeksfoGeeks A Computer Science Portal For Geeks.
Program 2:
<?php // Creating SplFile Object $gfg = new SplFileObject(__FILE__); while (!$gfg->eof()) { echo $gfg->fgets(); } ?> |
<?php
// Creating SplFile Object
$gfg = new SplFileObject(__FILE__);
while (!$gfg->eof()) {
echo $gfg->fgets();
}
?>
Reference: http://php.net/manual/en/splfileobject.fgets.php
Recommended Posts:
- PHP | fgets( ) Function
- PHP | SplFileObject eof() Function
- PHP | SplFileObject seek() Function
- PHP | SplFileObject rewind() Function
- PHP | SplFileObject fgetss() Function
- PHP | SplFileObject ftruncate() Function
- PHP | SplFileObject ftell() Function
- PHP | SplFileObject fstat() Function
- PHP | SplFileObject fwrite() Function
- PHP | SplFileObject fread() Function
- PHP | SplFileObject setMaxLineLen() Function
- PHP | SplFileObject flock() Function
- PHP | SplFileObject getMaxLineLen() Function
- PHP | SplFileObject fputcsv() Function
- PHP | SplFileObject current( ) Function
- PHP | SplFileObject fgetc() Function
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

