Move the file pointer back to the file’s beginning after reading the first line from the open file:
<?php $file = fopen(“test.txt”,“r”); // Read first line echo fgets($file); // Move back to beginning of file fseek($file,0); fclose($file); ?> |
An open file is sought in with the fseek() function.
This function shifts the file pointer, forward or backward, by the number of bytes, from its present location.
Help: Use ftell() to determine the current location!
fseek(file, offset, whence) |
Parameter |
Description |
file |
Essential. indicates which open file to look for in |
offset |
Essential. identifies the new location, measured in bytes starting at the file’s beginning. |
whence |
Not required. SEEK_SET – Set position equal to offset – is one possible value. By Default |
Return Value: |
If successful, 0; if not, -1 |
PHP Version: |
4.0+ |