Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP fseek() Function

PHP fseek() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The fseek() function seeks within an open file.

This function moves the file pointer forward or backward from its current position to a new position, measured in bytes from the beginning of the file.

Returns 0 on success, or -1 on failure. Note that seeking past the end of file (EOF) does not produce an error.

Syntax

fseek(file,offset,whence)

Parameters Description
file Required. Specifies the file in which to seek.
offset Required. Specifies the new position (measured in bytes from the beginning of the file).
whence Optional. (Added in PHP 4). Possible values:
  • SEEK_SET - Sets the position equal to offset. Default.
  • SEEK_CUR - Sets the position to the current position plus offset.
  • SEEK_END - Sets the position to the end of file (EOF) plus offset (to move to a position before the end of the file, offset must be negative).
  • |

    Tips and Notes

    **Tip:** Use ftell() to find the current position!


    Example


    PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual