PHP Ftell () Function

PHP

Syntax:
ftell ($file)
Parameters used:PHP's ftell() function only accepts one parameter $file. This is a required parameter and specifies the file.Returned value:Returns the current file pointer position on success, or FALSE on error.Exceptions :
  • Some filesystem functions may return unexpected results for files larger than 2 GB because PHP's integer type is signed and many platforms use 32-bit integers.
  • When opening a file for reading and writing with fopen (' file & # 39 ;, ' a + '), the file pointer must be at the end of the file.
  • Examples:
    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
    The following programs illustrate the ftell() function:Program 1 : In the program below, a file named gfg.txt contains the following content. Geeksforengineer is a portal for engineer! // Open the file in read mode. Mode $myfile = fopen ( "gfg.txt" , " r " );  
    // display the current index position in the open file echo ftell ( $myfile );  
    // close the file fclose ( $myfile ); ?>
    Output:
    0
    Program 2 : In the program below, the file named gfg.txt contains the following content. Geeksforengineer is a portal for engineer!
    // Open the file in reading mode. Mode $myfile = fopen ( "gfg.txt" , " r " );  
    // display the current index position in the open file echo ftell ( $myfile );  
    // change the current position fseek ( $myfile , "36" );  
    // display the current position echo "< br / >" . ftell ( $myfile );  
    // close the file fclose ( $myfile ); ?>
    Output:
    0 36
    Link: http: // php. net / manual / en / function.ftell.php



    Get Solution for free from DataCamp guru