Open In App

PHP | SplFileObject seek() Function

Last Updated : 24 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The SplFileObject::seek() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to seek to specify the line. Syntax:
void SplFileObject::seek( $line_num)
Parameters: This functions accept only one parameter $line_num which specifies the line number of the file. Return values: This function does not return any value. Below Programs illustrate the SplFileObject::seek () function in PHP: Program-1: php
<?php

// PHP program to illustrate
// SplFileObject Seek function

$file = new SplFileObject(__FILE__);

$file->seek(3);

echo $file->current();
?>
Output:
// SplFileObject Seek function
Program-2: php
<?php 
 
// PHP program to use array to check 
// multiple files 
$GFG = array(
    "/home/rajvir/Desktop/GeeksforGeeks/dummy.php",
    "gfg.txt",
    "mime.php"
    );
 
foreach ($GFG as &$file_name) { 
 
    $file = new SplFileObject($file_name);
    $file->seek(3);
    echo $file->current();
    }
?>
Output:
GeeksforGeeks
gfg
contribute
Reference: http://php.net/manual/en/splfileobject.seek.php

Next Article

Similar Reads