大网数据广告活动
PHP 语言与运行手册

dio_seek · 在 fd 指定 pos 位置

· 52CE 我爱测

SEEK_END - 指定 pos 是从文件结尾计算的字符数。负数指定文件当前范围内的位置;正数指定超过当前末端的位置。 如果将位置设置为超过当前末尾并写入数据,将用零将文件扩展到该位置。

dio_seek

(PHP 4 >= 4.2.0, PHP 5 < 5.1.0)

dio_seek — 在 fd 指定 pos 位置

说明

function dio_seek(resource $fd, int $pos, int $whence = SEEK_SET): int

函数 dio_seek() 用于更改给定文件描述符的文件当前读/写位置。

参数

fd

由 dio_open() 返回的文件描述符。

pos

新位置。

whence

指定如何解释 pos 的位置:

  • SEEK_SET (默认)- 从文件开头指定 pos。

  • SEEK_CUR - 指定 pos 是从文件当前位置计算的字符数。数量可以是正数或负数。

  • SEEK_END - 指定 pos 是从文件结尾计算的字符数。负数指定文件当前范围内的位置;正数指定超过当前末端的位置。 如果将位置设置为超过当前末尾并写入数据,将用零将文件扩展到该位置。

返回值

示例

示例 #1 在文件中定位

<?php

$fd = dio_open('/dev/ttyS0', O_RDWR);

dio_seek($fd, 10, SEEK_SET);
// position is now at 10 characters from the start of the file

dio_seek($fd, -2, SEEK_CUR);
// position is now at 8 characters from the start of the file

dio_seek($fd, -5, SEEK_END);
// position is now at 5 characters from the end of the file

dio_seek($fd, 10, SEEK_END);
// position is now at 10 characters past the end of the file. 
// The 10 characters between the end of the file and the current
// position are filled with zeros.

dio_close($fd);
?>

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。