PHP | SplFileObject fread() Function Last Updated : 20 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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 length to be read from file in bytes. Return values: This function returns the string read from the file on success or false on failure. Note: It make sure the file used in below program named as gfg.txt should have read permissions. Below Programs illustrate the SplFileObject::fread() function in PHP: Program 1: php <?php // Create an Object $file = new SplFileObject("gfg.txt", "r"); // Read 5 bytes from file $gfg = $file->fread(5); // Print Result echo ($gfg); ?> Output: Geeks Program 2: php <?php // PHP program to use array to check // multiple files $GFG = array( "dummy.txt", "gfg.txt", "frame.txt" ); foreach ($GFG as &$file_name) { // Create new SplFile Object $file = new SplFileObject($file_name, "r"); $contents = $file->fread(13); echo $contents . "</br>"; } ?> Output: GeeksforGeeks GeeksforGeeks GeeksforGeeks Reference: http://php.net/manual/en/splfileobject.fread.php Comment More infoAdvertise with us Next Article PHP | SplFileObject fread() Function R R_Raj Follow Improve Article Tags : Web Technologies 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 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 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 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 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