rewind

Rewind the position of a file pointer

Syntax

rewind ( resource $handle ) : bool

Parameters

handle

The file pointer must be valid, and must point to a file successfully opened by fopen().

Return

Returns TRUE on success or FALSE on failure.

Examples

<?

$filename = 'rewind.txt';
$mode = 'r+';

$handle = fopen($filename, $mode);

    fwrite($handle, 'Really long sentence');
    
    rewind($handle);
    fwrite($handle, 'Hello,');
    
    rewind($handle);
    fpassthru($handle);

fclose($handle);

?>
Hello, long sentence

PHP

Home Menu