php8.5
Home/ Manual/ spl / splfileobject/ SplFileObject::seek

SplFileObject::seek

PHP function Edit on GitHub ✎

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Seek to specified line

Description

SplFileObject::seek(int $line): void

Seek to specified line in the file.

Parameters

line

The zero-based line number to seek to.

Return Values

Void

Errors/Exceptions

Throws a LogicException if the line is negative.

Examples

SplFileObject::seek example

This example outputs the third line of the script which is found at position 2.

php
<?php
$file = new SplFileObject(__FILE__);
$file->seek(2);
echo $file->current();
?>

The above example will output something similar to:

output
$file->seek(2);

See Also

  • SplFileObject::current
  • SplFileObject::key
  • SplFileObject::next
  • SplFileObject::rewind
  • SplFileObject::valid

Source: reference/spl/splfileobject/seek.xml · from the official PHP manual (php/doc-en)