首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SplFileObject::fseek

(PHP 5 >= 5.1.0, PHP 7)

SplFileObject::fseek — Seek to a position

Description

代码语言:javascript
复制
public int SplFileObject::fseek ( int $offset [, int $whence = SEEK_SET ] )

Seek to a position in the file measured in bytes from the beginning of the file, obtained by adding offset to the position specified by whence.

Parameters

offset

The offset. A negative value can be used to move backwards through the file which is useful when SEEK_END is used as the whence value.

whence

whence values are:

  • SEEK_SET - Set position equal to offset bytes.
  • SEEK_CUR - Set position to current location plus offset.
  • SEEK_END - Set position to end-of-file plus offset.

If whence is not specified, it is assumed to be SEEK_SET.

Return Values

Returns 0 if the seek was successful, -1 otherwise. Note that seeking past EOF is not considered an error.

Examples

Example #1 SplFileObject::fseek() example

代码语言:javascript
复制
<?php
$file?=?new?SplFileObject("somefile.txt");

//?Read?first?line
$data?=?$file->fgets();

//?Move?back?to?the?beginning?of?the?file
//?Same?as?$file->rewind();
$file->fseek(0);
?>

See Also

  • fseek() - Seeks on a file pointer

← SplFileObject::fscanf

SplFileObject::fstat →

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com