gzseek

it to to

簡介

gzseek—Seekonagz-filepointer

說明

intgzseek(resource$zp,int$offset[,int$whence=SEEK_SET])
Setsthefilepositionindicatorforthegivenfilepointertothegivenoffsetbyteintothefilestream.Equivalenttocalling(inC)gzseek(zp,offset,SEEK_SET).
Ifthefileisopenedforreading,thisfunctionisemulatedbutcanbeextremelyslow.Ifthefileisopenedforwriting,onlyforwardseeksaresupported;gzseek()thencompressesasequenceofzeroesuptothenewstartingposition.

參數

zp
Thegz-filepointer.Itmustbevalid,andmustpointtoafilesuccessfullyopenedbygzopen().
offset
Theseekedoffset.
whence
whencevaluesare:
SEEK_SET-Setpositionequaltooffsetbytes.
SEEK_CUR-Setpositiontocurrentlocationplusoffset.
Ifwhenceisnotspecified,itisassumedtobeSEEK_SET.

返回值

Uponsuccess,returns0;otherwise,returns-1.NotethatseekingpastEOFisnotconsideredanerror.

範例

範例1

<?php
$gz=gzopen('somefile.gz','r');
gzseek($gz,2);
echogzgetc($gz);
gzclose($gz);
?>
參見
gztell()-Tellgz-filepointerread/writeposition
gzrewind()-Rewindthepositionofagz-filepointer

範例2

PHP/4.3.9
contrarytothenotes,gzseek()returns-1ifItrytoseekpasttheendofthefile.hereisafunctionthatwillreturnthelastseekableposition,andputthefilepointerthere.
/**setsthefilepointerattheendofthefile
*andreturnsthenumberofbytesinthefile.
*/
functiongzend($fh)
{
$d=1<<14;
$eof=$d;
while(gzseek($fh,$eof)==0)$eof+=$d;
while($d>1)
{
$d>>=1;
$eof+=$d*(gzseek($fh,$eof)?-1:1);
}
return$eof;
}

相關詞條

熱門詞條

聯絡我們