Share on Google+Share on Google+

PHP function rewind() and example

Advertisement
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

Advertisements

Advertisement

Posted on: October 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.