PHP fseek() 函数

PHP 教程 · 2019-01-25 08:29:47

定义和用法

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

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

如果成功该函数返回 0,如果失败则返回 -1。请注意,移动到文件末尾(EOF)之后的位置不会产生错误。

语法


fseek(file,offset,whence)


参数 描述
file 必需。规定要在其中定位的文件。
offset 必需。规定新的位置(从文件头开始以字节数度量)。
whence 可选。(PHP 4 中新增的)。 可能的值:
  • SEEK_SET - 设定位置等于 offset。默认。
  • SEEK_CUR - 设定位置为当前位置加上 offset。
  • SEEK_END - 设定位置为文件末尾(EOF)加上 offset(要移动到文件末尾之前的位置,offset 必须是一个负值)。

提示和注释

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

实例


<?php
$file = fopen("test.txt","r");
// read first line
fgets($file);
// move back to beginning of file
fseek($file,0);
?>


点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Scalable Internet Architectures

Scalable Internet Architectures

Theo Schlossnagle / Sams Publishing / 2006-7-31 / USD 49.99

As a developer, you are aware of the increasing concern amongst developers and site architects that websites be able to handle the vast number of visitors that flood the Internet on a daily basis. Sc......一起来看看 《Scalable Internet Architectures》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码