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