Skip to content
Related Articles

Related Articles

PHP | SplFileObject seek() Function
  • Last Updated : 24 Dec, 2018

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :