rewind

bool rewind(resource file_handle) 

Rewinds a file pointer.

Returns:

TRUE on success; FALSE on error

Description:

Use this function to “rewind” a file pointer. It resets the pointer associated with the specified file handle to the beginning of the file.

Example:

Rewind a file pointer
$fh = fopen ("test.txt", "r"); 

while(!feof($fh)) {
    $output = htmlspecialchars (fgets ($fh, 1024)); 
    echo ("$output<br />"); 
} 

// start again and read a line 
rewind ($fh); 
echo (fgets($fh, 1024)); 

fclose ($fh); 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.