Php/func filesystem fseek
来自菜鸟教程
PHP fseek()函数
例
从打开的文件中读取第一行,然后将文件指针移回文件的开头:
<?php
$file = fopen("test.txt","r");
// Read first line
echo fgets($file);
// Move back to beginning of file
fseek($file,0);
fclose($file);
?>
定义和用法
fseek()函数在打开的文件中查找。
此函数将文件指针从当前位置移动到新位置,该位置由字节数指定向前或向后。
Tip: 您可以使用ftell()找到当前位置!
句法
fseek(file, offset, whence)
参数值
| 参数 | 描述 |
|---|---|
| file | 需要。指定要查找的打开文件 |
| offset | 需要。指定新位置(从文件开头开始以字节为单位) |
| whence |
可选的。可能的值:
|
技术细节
| 返回值: | 成功时为0,否则为-1 |
| PHP版本: | 4.0+ |