ftell()函數(shù)可以返回打開文件中的當(dāng)前位置。成功時返回當(dāng)前文件指針位置,失敗時返回false。
int ftell ( resource $handle )
該函數(shù)可以返回句柄引用的文件指針的位置,這意味著其在文件流中的偏移量。
<?php
$file = fopen("/PhpProject/sample.txt", "r");
//打印當(dāng)前位置
echo ftell($file);
//更改當(dāng)前位置
fseek($file, "10");
//再次打印當(dāng)前位置
echo "\n" . ftell($file);
fclose($file);
?>輸出結(jié)果
0 10
<?php
//打開文件并讀取數(shù)據(jù)
$file = fopen("/PhpProject/sample.txt", "r");
$data = fgets($file, 7);
echo ftell($file);
fclose($file);
?>輸出結(jié)果
6