PHP中的ftell()函數是一個內置函數,用於返回打開文件中的當前位置。該文件將作為參數發送到ftell()函數,如果成功,則返回當前文件指針位置;如果失敗,則返回FALSE。
用法:
ftell( $file )
使用的參數:PHP中的ftell()函數僅接受一個參數$file。它是指定文件的必需參數。
返回值:成功時返回當前文件指針位置,失敗時返回FALSE。
異常:
- 由於PHP的整數類型是帶符號的,並且許多平台使用32位整數,因此某些文件係統函數可能會對大於2GB的文件返回意外結果。
- 當通過fopen('file','a +')打開文件進行讀寫時,文件指針應位於文件末尾。
例子:
Input : $myfile = fopen("gfg.txt", "r");
        echo ftell($myfile);
Output : 0
Input : $myfile = fopen("gfg.txt", "r");
        echo ftell($myfile);
        fseek($myfile, "36");
        echo ftell($myfile);
Output : 0
         36
以下示例程序旨在說明ftell()函數:
程序1::在下麵的程序中,名為gfg.txt的文件包含以下內容。
Geeksforgeeks is a portal for geeks!
<?php 
// Opening a file in read. mode 
$myfile = fopen("gfg.txt", "r"); 
  
// displaying the current position of the pointer in the opened file 
echo ftell($myfile); 
  
// closing the file 
fclose($myfile); 
?>輸出:
0
程序2::在下麵的程序中,名為gfg.txt的文件包含以下內容。
Geeksforgeeks is a portal for geeks!
<?php 
// Opening a file in read. mode 
$myfile = fopen("gfg.txt", "r"); 
  
// displaying the current position of the pointer in the opened file 
echo ftell($myfile); 
  
// chnaging current position 
fseek($myfile, "36"); 
  
//displaying current position 
echo "<br />" . ftell($myfile); 
  
// closing the file 
fclose($myfile); 
?>輸出:
0 36
參考: http://php.net/manual/en/function.ftell.php
相關用法
- PHP SplFileObject ftell()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js nfs()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP cos( )用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP pow( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- CSS var()用法及代碼示例
注:本文由純淨天空篩選整理自Shubrodeep Banerjee大神的英文原創作品 PHP | ftell() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
