Read first line from the open file, then move the file pointer back to the beginning of the file:
<?php
$file = fopen("test.txt","r");
// Read first line
echo fgets($file);
// Move back to beginning of file
fseek($file,0);
fclose($file);
?>
Run Example »
The fseek() function seeks in an open file.
This function moves the file pointer from its current position to a new position, forward or backward, specified by the number of bytes.
Tip: You can find the current position by using ftell()!
fseek(
file,
offset,
whence)
Parameter | Description |
---|---|
file | Required. Specifies the open file to seek in |
offset | Required. Specifies the new position (measured in bytes from the beginning of the file) |
whence | Optional. Possible values:
|
Return Value: | 0 on success, otherwise -1 |
---|---|
PHP Version: | 4.0+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!