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
- PHP | SplFixedArray rewind() Function
- PHP | SplFileObject rewind() Function
- PHP | SimpleXMLIterator rewind() Function
- PHP | SplDoublyLinkedList rewind() Function
- PHP | SplObjectStorage rewind() Function
- PHP | Ds\Set first() Function
- PHP | Ds\Set contains() Function
- PHP | pi( ) Function
- PHP | each() Function
- PHP | key() Function
- PHP | Ds\Map put() Function
- PHP | Ds\Map xor() Function
- D3.js | d3.map.set() 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.