Home>Article>Backend Development> PHP fseek函数有什么用

PHP fseek函数有什么用

PHPz
PHPz Original
2016-06-07 17:22:31 1913browse

PHP fseek函数有什么用

PHP fseek函数有什么用?

定义和用法

fseek() 函数在打开的文件中定位。

该函数把文件指针从当前位置向前或向后移动到新的位置,新位置从文件头开始以字节数度量。

成功则返回 0;否则返回 -1。注意,移动到 EOF 之后的位置不会产生错误。

语法

fseek(file,offset,whence)

参数

file 必需。规定要在其中定位的文件。

offset 必需。规定新的位置(从文件头开始以字节数度量)。

whence 可选。可能的值:

SEEK_SET - 设定位置等于 offset 字节。默认。

SEEK_CUR - 设定位置为当前位置加上 offset。

SEEK_END - 设定位置为文件末尾加上 offset (要移动到文件尾之前的位置,offset 必须是一个负值)。

说明

whence 参数是 PHP 4.0.0 之后增加的。

提示和注释

提示:通过使用 ftell() 来找到当前位置。

例子

更多相关技术文章,请访问PHP中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn