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// 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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions