PHP | SplFileObject ftell() Function

The SplFileObject::ftell() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to return the position of the file pointer which specifies the current offset in the file.

Syntax:

int SplFileObject::ftell( void )

Parameters: This function does not accept any parameters.

Return values: This function returns the position of the file pointer.

Below Programs illustrate the SplFileObject::ftell() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an Spl Object
$file = new SplFileObject("gfg.txt");
  
// Read line from file
$data = $file->fgets();
  
// Print position 
echo $file->ftell();
?>

chevron_right


Output:

13

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create an Array
$GFG = array(
    "dummy.txt",
    "gfg.txt",
    "frame.txt"
);
   
// Loop to read each file
foreach ($GFG as &$arr) {
      
    // Creating Spl Object
    $file = new SplFileObject($arr);
       
    // Function to read first line
    $data = $file->fgets();
       
    // Display result
    echo $file->ftell() . "</br>";
}
?>

chevron_right


Output:

13
15
13

Reference: http://php.net/manual/en/splfileobject.ftell.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.