fseek() function in PHP

PHPProgrammingServer Side Programming

The fseek() function seeks in an open file. It returns 0 on success, else returns -1 on failure.

Syntax

fseek(file_pointer, offset, whence)

Parameters

  • file_pointer − A file pointer created using fopen(). Required.

  • offset − Specify the new position. Required.

  • whence − The following are the values:

    • SEEK_SET - Set position equal to offset bytes. Default.
    • SEEK_CUR - Set position to current location plus offset.
    • SEEK_END - Set position to end-of-file plus offset.

Return

The fseek() function returns 0 on success, else returns -1 on failure.

Example

<?php
   $file_pointer = fopen("new.txt", "w");
   fgets($file_pointer);
   // move back to the beginning of file
   echo fseek($file_pointer, 0);
   fclose($myfile);
?>

Output

0
raja
Published on 03-Oct-2018 16:25:16
Advertisements