Current Location: Home> Function Categories> fseek

fseek

Positioning in file pointer
Name:fseek
Category:File system
Programming Language:php
One-line Description:Locate in the open file.

Definition and usage

fseek() function is located in the open file.

This function moves the file pointer forward or backward from the current position to a new position, which starts at the file header by the number of bytes.

If successful, return 0; otherwise, return -1. Note that no error occurs when moving to the position after EOF.

Example

 <?php
$file = fopen ( "test.txt" , "r" ) ;

// Read the first line
fgets ( $file ) ;

// Rewind back to the beginning of the file
fseek ( $file , 0 ) ;
?>

grammar

 fseek ( file , offset , when )
parameter describe
file Required. Specify the files to be located in it.
offset Required. Specifies a new location (measured by bytes starting from the file header).
when Optional. Possible values:
  • SEEK_SET - Set position equal to offset bytes. default.
  • SEEK_CUR - Set the position to the current position plus offset .
  • SEEK_END - Set the position to add offset to the end of the file (to move to the position before the end of the file, offset must be a negative value).

illustrate

Whence parameter is added after PHP 4.0.0.

Similar Functions
Popular Articles