fseek

(PHP 4, PHP 5, PHP 7)

fseek锟斤拷锟侥硷拷指锟斤拷锟叫讹拷位

说锟斤拷

fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] ) : int

锟斤拷锟斤拷 handle 锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟借定锟侥硷拷指锟斤拷位锟矫★拷 锟斤拷位锟矫达拷锟侥硷拷头锟斤拷始锟斤拷锟街斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 whence 指锟斤拷锟斤拷位锟矫硷拷锟斤拷 offset锟斤拷

In general, it is allowed to seek past the end-of-file; if data is then written, reads in any unwritten region between the end-of-file and the sought position will yield bytes with value 0. However, certain streams may not support this behavior, especially when they have an underlying fixed size storage.

锟斤拷锟斤拷

handle

锟侥硷拷系统指锟诫,锟角碉拷锟酵碉拷锟斤拷 fopen() 锟斤拷锟斤拷锟斤拷 resource(锟斤拷源)锟斤拷

offset

偏锟斤拷锟斤拷锟斤拷

要锟狡讹拷锟斤拷锟侥硷拷尾之前锟斤拷位锟矫o拷锟斤拷要锟斤拷 offset 锟斤拷锟斤拷一锟斤拷锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷 whenceSEEK_END锟斤拷

whence

whence values are:

  • SEEK_SET - 锟借定位锟矫碉拷锟斤拷 offset 锟街节★拷
  • SEEK_CUR - 锟借定位锟斤拷为锟斤拷前位锟矫硷拷锟斤拷 offset锟斤拷
  • SEEK_END - 锟借定位锟斤拷为锟侥硷拷尾锟斤拷锟斤拷 offset锟斤拷

锟斤拷锟斤拷值

锟缴癸拷锟津返伙拷 0锟斤拷锟斤拷锟津返伙拷 -1锟斤拷注锟斤拷锟狡讹拷锟斤拷 EOF 之锟斤拷锟轿伙拷貌锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

Example #1 fseek() 锟斤拷锟斤拷

<?php

$fp 
fopen('somefile.txt''r');

// read some data
$data fgets($fp4096);

// move back to the beginning of the file
// same as rewind($fp);
fseek($fp0);

?>

注锟斤拷

Note:

锟斤拷锟绞癸拷酶锟斤拷锟侥o拷裕锟�a 锟斤拷 a+锟斤拷锟斤拷锟轿猴拷写锟斤拷锟侥硷拷锟斤拷锟捷讹拷锟结被锟斤拷锟斤拷锟斤拷去锟斤拷锟斤拷锟侥硷拷锟斤拷位锟矫斤拷锟结被锟斤拷锟皆o拷锟斤拷锟斤拷 fseek() 锟侥斤拷锟斤拷锟轿达拷锟斤拷濉�

Note:

Not all streams support seeking. For those that do not support seeking, forward seeking from the current position is accomplished by reading and discarding data; other forms of seeking will fail.

锟轿硷拷

  • ftell() - 锟斤拷锟斤拷锟侥硷拷指锟斤拷锟�/写锟斤拷位锟斤拷
  • rewind() - 锟斤拷锟斤拷锟侥硷拷指锟斤拷锟轿伙拷锟�