PHP fseek () function
Definition and Usage
fseek () function located in the open file.
This function resets the file pointer from the current position or move forward and backward to the new location, the new location from the beginning of the file measured in bytes.
The function returns 0 if successful, or -1 if it fails. Please note that position to the end of the file (EOF) After no errors.
grammar
fseek(file,offset,whence)
参数 | 描述 |
---|---|
file | 必需。规定要在其中定位的文件。 |
offset | 必需。规定新的位置(从文件头开始以字节数度量)。 |
whence | 可选。(PHP 4 中新增的)。 可能的值:
|
Tips and Notes
Tip: By using ftell () to find the current location!
Examples
<?php
$file = fopen("test.txt","r");
// read first line
fgets($file);
// move back to beginning of file
fseek($file,0);
?>
$file = fopen("test.txt","r");
// read first line
fgets($file);
// move back to beginning of file
fseek($file,0);
?>
Complete PHP Filesystem Reference Manual