PHP fseek() Function

P
PHP fstat() Function
PHP unlink() Function

In this article, you will learn how to move the file pointer in PHP. The fseek() function in PHP moves the file pointer from its current position to a new position, forward or backward, specified by the number of bytes. ftell() method returns the current location of the file pointer.

what is the syntax of the FSEEK function in php?

fseek(file, offset, whence)
ParameterDescription
fileRequired. Specifies the open file to seek in
offsetRequired. Specifies the new position (measured in bytes from the beginning of the file)
whenceOptional. Possible values:SEEK_SET – Set position equal to offset. DefaultSEEK_CUR – Set position to current location plus offsetSEEK_END – Set position to EOF plus offset (to move to a position before EOF, the offset must be a negative value)
PHP fseek() method

examples of the FSEEK function

Example 1. In this example, we read the first line from the open file, then move the file pointer back to the beginning of the file.

<?php
$file = fopen("test.txt","r");
// Read first line
echo fgets($file);
// Move back to beginning of file
fseek($file,0);
fclose($file);
?>
PHP fstat() Function
PHP unlink() Function

Add comment

Tutor Network

Share this

Learn PHP from A to Z