
ftell()函数可以返回打开文件中的当前位置。成功时返回当前文件指针位置,失败时返回false。
语法
int ftell ( resource $handle )
该函数可以返回句柄引用的文件指针的位置,这意味着其在文件流中的偏移量。
示例1
<?php
$file = fopen("/PhpProject/sample.txt", "r");
//打印当前位置
echo ftell($file);
//更改当前位置
fseek($file, "10");
//再次打印当前位置
echo "\n" . ftell($file);
fclose($file);
?>输出结果
0 10
示例2
<?php
//打开文件并读取数据
$file = fopen("/PhpProject/sample.txt", "r");
$data = fgets($file, 7);
echo ftell($file);
fclose($file);
?>输出结果
6