PHP - Fonction ftell ()

La fonction ftell () peut renvoyer la position actuelle dans un fichier ouvert. Il peut renvoyer la position actuelle du pointeur de fichier en cas de succès ou false en cas d'échec.

Syntaxe

int ftell ( resource $handle )

Cette fonction peut renvoyer la position du pointeur de fichier référencé par la poignée, ce qui signifie son décalage dans le flux de fichier.

Exemple 1

<?php
   $file = fopen("/PhpProject/sample.txt", "r");

   // print current position
   echo ftell($file);

   // change current position
   fseek($file, "10");

   // print current position again
   echo "\n" . ftell($file);

   fclose($file);
?>

Production

0
10

Exemple-2

<?php
   // opens a file and read data
   $file = fopen("/PhpProject/sample.txt", "r");
   $data = fgets($file, 7);

   echo ftell($file); 
   fclose($file);
?>

Production

6