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
$file = new SplFileObject( __FILE__ );
$file ->seek(3);
echo $file ->current();
?>
|
Output:
// SplFileObject Seek function
Program-2:
<?php
$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
Share your thoughts in the comments
Please Login to comment...