PHP fseek() Function
Definition and Usage
fseek() function locates in the opened file.
This function moves the file pointer from the current position to a new position in the file, measured from the beginning of the file in bytes.
Returns 0 on success; otherwise, returns -1. Note that moving to a position after EOF does not produce an error.
Syntax
fseek(file,offset,whence)
Parameters | Description |
---|---|
file | Required. Specifies the file in which to locate. |
offset | Required. Specifies the new position (measured in bytes from the beginning of the file). |
whence |
Optional. Possible values:
|
Description
whence The parameter was added in PHP 4.0.0 and later.
Tips and Comments
Tip:By using ftell() to find the current position.
Example
<?php $file = fopen("test.txt","r"); // Read the first line fgets($file); // Go back to the beginning of the file fseek($file,0); ?>