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
lineThe 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::currentSplFileObject::keySplFileObject::nextSplFileObject::rewindSplFileObject::valid