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);
?>
