PHP | SplFileObject current( ) Function Last Updated : 19 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The SplFileObject::current() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get current line of file. Syntax: string SplFileObject::current( void ) Parameters: This function does not accept any parameter. Return values: Returns current line of the file. Below Programs illustrate the SplFileObject::current() function in PHP. Note: Program 1 has used gfg.txt file that contains following data. GeeksforGeeks A Computer Science Portal for Geeks Program 1: Print All lines of file one by one. php <?php // Creating SplFile Object $file = new SplFileObject("gfg.txt"); foreach ($file as $gfg => $line) { echo $file->key() + 1 ." Line". ':> ' . $file->current(); } ?> Output: 1 Line: GeeksforGeeks 2 Line: A Computer Science 3 Line: Portal for Geeks Program 2: Print all lines of current file. php <?php // Create SplFileObject object $file = new SplFileObject(__FILE__); // Print all characters of file while (false !== ($gfg = $file->fgetc())) { echo "$gfg"; } ?> Output: 1 Line:<?php 2 Line: 3 Line: // Creating SplFile Object 4 Line: $file = new SplFileObject(__FILE__); 5 Line: 6 Line: foreach ($file as $k => $line) { 7 Line: echo $file->key() + 1 ." Line". 8 Line: ': ' . $file->current(); 9 Line: } 10 Line: ?> Reference: http://php.net/manual/en/splfileobject.current.php Comment More infoAdvertise with us Next Article PHP | SplFileObject current( ) Function R R_Raj Follow Improve Article Tags : PHP PHP-function PHP-SplFileInfo Similar Reads PHP | SplFileObject fgets() Function The SplFileObject::fgets() function is an inbuilt function of the Standard PHP Library (SPL) in PHP which is used to get a line from the file. Syntax: string SplFileObject::fgets( void ) Parameters: This function does not accept any parameter. Return values: This function returns a string contain 1 min read PHP | SplFileObject fgetc() Function The SplFileObject::fgetc() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get character from file. Syntax: string SplFileObject::fgetc( void ) Parameters: This function does not accept any parameter. Return values: Returns single character read from the file or 1 min read PHP | SplFileObject eof() Function The SplFileObject::eof() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used reached end of file. Syntax: string SplFileObject::eof( void ) Parameters: This function does not accept any parameter. Return values: Returns TRUE on Success. Below Programs illustrate the Sp 1 min read PHP | SplFileObject fread() Function The SplFileObject::fread() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to reads the given number of bytes from the file. Syntax: string SplFileObject::fread( $length ) Parameters: This function accepts single parameter $length which is used to specify the lengt 1 min read PHP | SplFileObject fgetss() Function The SplFileObject::fgetss() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get line from file and strip HTML tags.Syntax:  string SplFileObject::fgetss( $tags) Parameters: This function accept only one parameter $tags an optional parameter to specify tags whic 1 min read Like