PHP | SplFileObject setMaxLineLen() Function

The SplFileObject::setMaxLineLen() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to set the maximum length of line length.

Syntax:

void SplFileObject::setMaxLineLen( $len )

Parameters: This function accepts single parameter $len which is used to specify the maximum length of line.



Return values: This function returns the maximum length of line. The default value is 0.

Below Programs illustrate the SplFileObject::setMaxLineLen() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an SplFile Object
$gfg = new SplFileObject("gfg.txt");
  
// Print Length
var_dump($gfg->getMaxLineLen());
  
// Set length 
$gfg->setMaxLineLen(20);
var_dump($gfg->getMaxLineLen());
  
?>

chevron_right


Output:

int(0) int(20)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an Array
$GFG = array(
    "dummy.txt",
    "gfg.txt",
    "frame.txt"
    );
  
// Creating Spl Object
foreach ($GFG as &$arr
{
    // Create an SplFile Object
    $gfg = new SplFileObject($arr);
  
    // Print Length before
    var_dump($gfg->getMaxLineLen());
  
    // Set length 
    $gfg->setMaxLineLen(50);
    echo "After = ";
    // Print length after
    var_dump($gfg->getMaxLineLen());
  
    echo "</br>";
    }
?>

chevron_right


Output:

int(0) After = int(50) 
int(0) After = int(50) 
int(0) After = int(50) 

Reference: http://php.net/manual/en/splfileobject.setmaxlinelen.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.