Open In App

PHP | SplFileObject seek() Function

Last Updated : 24 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
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 program to illustrate
// SplFileObject Seek function
  
$file = new SplFileObject(__FILE__);
  
$file->seek(3);
  
echo $file->current();
?>


Output:

// SplFileObject Seek function

Program-2:




<?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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads