fseek()函数可以在打开的文件中查找。此函数可以将文件指针从其当前位置向前或向后移动到新位置,该位置由字节数指定。成功时此函数可以返回0,失败时可以返回-1。寻找过去的EOF不会产生错误。
int fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] )
fseek()函数在与 handle 关联的文件中设定文件指针位置。 新位置从文件头开始以字节数度量,是以 whence 指定的位置加上 offset。
<?php
$file = fopen("/PhpProject/sample.txt", "r");
//读第一行
echo fgets($file);
//移回文件开头
fseek($file, 0);
echo fgets($file);
?>
输出结果
nhooo nhooo