PHP rewind() Function
In this chapter you will learn:
- Definition for PHP rewind() Function
- Syntax for PHP rewind() Function
- Parameter for PHP rewind() Function
- Return for PHP rewind() Function
- Example -
- Example - Seek and rewind
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
Parameter | Is Required | Description |
---|---|---|
file | Required. | 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// j a v a 2s .com
$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 j av a 2s . co m*/
$file = fopen("test.txt","r");
fseek($file,"15");//Change position of file pointer
rewind($file);//Set file pointer to 0
fclose($file);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP rewinddir() Function
- Syntax for PHP rewinddir() Function
- Parameter for PHP rewinddir() Function
- Example - resets the directory handle created by opendir()
Home » PHP Tutorial » PHP File Functions