The fseek() function locates within an open file.
This function moves the file pointer forward or backward from the current position to a new position, measured in bytes from the beginning of the file.
The function returns 0 if successful and -1 if failed. Note that moving to a position after the end of file (EOF) does not produce an error.
fseek(file,offset,whence)
parameter | describe |
---|---|
file | Required. Specifies the file to locate in. |
offset | Required. Specifies the new position (measured in bytes from the beginning of the file). |
whence | Optional. (New in PHP 4). Possible values: SEEK_SET - Set position equal to offset. default. SEEK_CUR - Sets the position to the current position plus offset. SEEK_END - Sets the position to the end of file (EOF) plus offset (to move to a position before the end of file, offset must be a negative value). |
Tip: Find the current position by using ftell()!
<?php$file = fopen("test.txt","r");// read first linefgets($file);// move back to the beginning of filefseek($file,0);?>