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://codercto.com/courses/l/5.html

查看所有标签

Sexy Web Design

Sexy Web Design

Elliot Stocks / SitePoint / 2009-03-28 / $39.95

Description A guide to building usable, aesthetically pleasing interfaces for web sites and web applications by applying timeless principles of user-centered design. This book focuses on practical ......一起来看看 《Sexy Web Design》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具