PHP fseek() 函數
定義和用法
fseek() 函數在打開的文件中定位。
該函數把文件指針從當前位置向前或向後移動到新的位置,新位置從文件頭開始以字節數度量。
如果成功該函數返回0,如果失敗則返回-1。 請注意,移動到文件末尾(EOF)之後的位置不會產生錯誤。
語法
fseek(file,offset,whence)
参数 | 描述 |
---|---|
file | 必需。规定要在其中定位的文件。 |
offset | 必需。规定新的位置(从文件头开始以字节数度量)。 |
whence | 可选。(PHP 4 中新增的)。 可能的值:
|
提示和註釋
提示:通過使用ftell()來找到當前位置!
實例
<?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);
?>
完整的PHP Filesystem參考手冊