PHP Tutorial - 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

ParameterIs RequiredDescription
fileRequired.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
      $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
$file = fopen("test.txt","r");
fseek($file,"15");//Change position of file pointer
rewind($file);//Set file pointer to 0
fclose($file);
?>