PHP 中的 fseek() 函数
phpprogrammingserver side programming更新于 2025/5/15 11:37:17
fseek() 函数在打开的文件中查找。成功时返回 0,失败时返回 -1。
语法
fseek(file_pointer, offset, whence)
参数
file_pointer − 使用 fopen() 创建的文件指针。必需。
offset − 指定新位置。必需。
whence − 以下是值:
- SEEK_SET - 将位置设置为等于偏移字节。默认。
- SEEK_CUR - 将位置设置为当前位置加上偏移量。
- SEEK_END - 将位置设置为文件末尾加上偏移量。
返回
fseek() 函数在成功时返回 0,否则在失败时返回 -1。
示例
<?php
$file_pointer = fopen("new.txt", "w");
fgets($file_pointer);
// 移回文件开头
echo fseek($file_pointer, 0);
fclose($myfile);
?>
输出
0

