ftell

(PHP 4, PHP 5, PHP 7, PHP 8)

ftell返回文件指针读/写的位置

说明

ftell(resource $stream): int|false

返回由 stream 指定的文件指针的位置,也就是文件流中的偏移量。

参数

stream

文件指针必须是有效的,且必须指向一个通过 fopen()popen() 成功打开的文件。在附加模式(加参数 "a" 打开文件)中 ftell() 会返回未定义错误。

返回值

以整数形式返回由 stream 引用的文件指针的位置,即文件流中的偏移量。

如果出错,返回 false

注意: 因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果。

范例

示例 #1 ftell() 例子

<?php

// opens a file and read some data
$fp = fopen("/etc/passwd", "r");
$data = fgets($fp, 12);

// where are we ?
echo ftell($fp); // 11

fclose($fp);

?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top