The fflush() function in PHP is an inbuilt function which is used to write all the buffered output to an open file. The fflush() function forces a write of all buffered output to the resource pointed to by the file handle. The fflush() function returns true on success and false on failure.
Parameters: The fflush() function in PHP accepts only one parameter which is $file. It specifies the open file stream.
Return Value: It returns TRUE on success and FALSE on failure.
Errors And Exception:
- The fflush() function results in errors if the file pointer is not valid.
- The file pointed must be opened by fopen() or fsockopen() and closed by fclose().
Below programs illustrate the fflush() function.
Program 1: In the below program the file named singleline.txt contains a single line of information which is “This file consists of a single line.”.
This file consists of a single line.
Program 2: In the below program the file named gfg.txt contains the following piece of 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 | dir() Function
- PHP | Ds\Set xor() Function
- PHP | Ds\Set add() Function
- p5.js | value() Function
- p5.js | nfs() Function
- D3.js | d3.min() function
- PHP | max( ) Function
- PHP | min( ) Function
- p5.js | nfp() Function
- PHP Ds\Map sum() Function
- D3.js | d3.map.set() Function
- D3.js | d3.rgb() 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 firstname.lastname@example.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.