PHP | rewind( ) Function
The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file.
Any data written to a file will always be appended if the file is opened in append (“a” or “a+”) mode regardless of the file pointer position.
The file on which the pointer has to be edited is sent as a parameter to the rewind() function and it returns True on success or False on failure.
The rewind() function in PHP accepts one parameter.
- file : It is a mandatory parameter which specifies the file to be edited.
It returns True on success or False on failure.
Errors And Exception:
- The rewind() function generates an E_WARNING level error on failure.
- The stream must be “seekable” for using the rewind() function.
- If the file is opened in append mode, the data written will be appended regardless of the position of the pointer.
Input: $myfile = fopen("gfg.txt", "r"); fseek($myfile, "10"); rewind($myfile); fclose($file); Output: 1 Input : $myfile = fopen("gfg.txt", "r+"); fwrite($myfile, 'geeksforgeeks'); rewind($myfile); fwrite($myfile, 'portal'); rewind($myfile); echo fread($myfile, filesize("gfg.txt")); fclose($myfile); Output : portalforgeeks Here all characters of the file as it is after rewind "portal"
Below are the programs to illustrate the rewind() function.
geeksportalks a computer science portal
My Personal Notes arrow_drop_up
Please Login to comment...