The rewind() function "rewinds" the position of the file pointer to the beginning of the file.
PHP rewind() Function has the following syntax.
rewind(file)
Parameter | Is Required | Description |
---|---|---|
file | Required. | Open file |
This function returns TRUE on success, or FALSE on failure.
rewind() moves the file pointer back to the beginning. rewind($handle) resets the file pointer $handle to the beginning.
<?PHP
$filename = "c:/abc/test.txt";
$handle = fopen($filename, "w+");
fwrite($handle, "java2s.com\n");
rewind($handle);
fwrite($handle, "o");
fclose($handle);
?>
Seek and rewind
<?php
$file = fopen("test.txt","r");
fseek($file,"15");//Change position of file pointer
rewind($file);//Set file pointer to 0
fclose($file);
?>