PHP function rewind() and example


 

PHP function rewind() and example

In this part of the tutorial we will learn about the function rewind in context of file handling. And also we will see the example related to the rewind function

In this part of the tutorial we will learn about the function rewind in context of file handling. And also we will see the example related to the rewind function

PHP rewind() Function Syntax

bool rewind(file_handle)

  • In file handling the file pointer goes to other position after reading the file.
  • rewind() function is used to set the pointer at the beginning position in the file.

Example of PHP rewind() Function

<?php
    $file
=fopen("roseindia.txt","r");
    echo
"<br>file pointer position ".ftell($file);
    fgets($file);
    fgets($file);
    echo
"<br>file pointer position ".ftell($file);
    rewind($file);
    echo
"<br>after rewind file pointer position ".ftell($file);
?>

Output

  • file pointer position 0
  • file pointer position 345
  • after rewind file pointer position 0

Ads