PHP | SplFileObject fgetc() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 FALSE on EOF. Below Programs illustrate the SplFileObject::fgetc() function in PHP. Note: Program 1 has used gfg.txt file that contains following data. GeeksforGeeks Program 1: Print All characters of file by one space separated. php <?php // Create SplFileObject object $file = new SplFileObject("gfg.txt"); // Print all characters of file while (false !== ($gfg = $file->fgetc())) { echo "$gfg"; } ?> Output: G e e k s f o r G e e k s Program 2: Print all characters 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: <?php // Create SplFileObject object $file = new SplFileObject(__FILE__); // Print all characters of file while (false !== ($gfg = $file->fgetc())) { echo "$gfg"; } ?> Reference: https://www.php.net/manual/en/splfileobject.fgetc.php Comment More infoAdvertise with us Next Article PHP | SplFileObject fgetss() 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 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 PHP | SplFileObject fstat() Function The SplFileObject::fstat() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to give the information of the file. Syntax: array SplFileObject::fstat( void ) Parameters: This function does not accept any parameter. Return values: This function returns an array which c 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 ftell() Function The SplFileObject::ftell() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to return the position of the file pointer which specifies the current offset in the file. Syntax: int SplFileObject::ftell( void ) Parameters: This function does not accept any parameters. 1 min read PHP SplFileObject fseek() Function The SplFileObject::fseek() function is an inbuilt function of Standard PHP Library (SPL) in PHP that allows you to move the file pointer to a specified position within a file opened using SplFileObject. The file pointer is the position where the next read or write operation will occur. This function 2 min read Like