The feof() function in PHP is an inbuilt function which is used to test for the end-of-file on a file pointer. It checks if the “end-of-file” has been reached or not. The feof() function is used for looping through the content of a file if the size of content is not known beforehand.
The feof() function returns True if end-of-file has been reached or if an error has occurred. Else it returns False.
feof( $file )
Parameters: The feof() function in PHP accepts only one parameter which is $file. This parameter specifies the file which has to be checked for end-of-file.
Return Value: It returns TRUE if end-of-file has been reached or if an error has occurred. Else it returns False.
Errors And Exception:
- It goes in an infinite loop if the passed file pointer is not valid, because end-of-file fails to return True.
- feof() function hangs if a connection opened by fsockopen() isn’t closed by the server.
Below programs illustrate the feof() function:
Program 1: In the below program the file named “singleline.txt” contains only a single line of text which is “This file consists of only a single line.”.
This file consists of only a single line.
Program 2: In the below program the file named “gfg.txt” contains the following text.
This is the first line.
This is the second line.
This is the third line.
This is the first line. This is the second line. This is the third line.
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.