English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Filesystem Reference Manual
The rewind() function can move the file pointer position back to the beginning of the file, and returns true on success and false on failure.
bool rewind ( resource $handle )
Set the file position pointer of the handle to the beginning of the file stream.
Note: If the file is opened in append mode ("a" or "a+Mode opens, any data written to the file is always appended to the end, regardless of the position of the file pointer.
<?php $handle = fopen("/PhpProject/sample.txt", "r+"); fwrite($handle, "Long sentence"); rewind($handle); fwrite($handle, "Hello PHP"); rewind($handle); echo fread($handle, filesize("/PhpProject/sample.txt")); fclose($handle); ?>
Output Result
Hello PHPence
<?php $file = fopen("/PhpProject/sample.txt", "r"); fseek($file, "15"); // Change the position of the file pointer rewind($file); // Set the file pointer to 0 fclose($file); ?>