Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | SplFileObject seek() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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


My Personal Notes arrow_drop_up
Last Updated : 24 Dec, 2018
Like Article
Save Article
Similar Reads
Related Tutorials