Thursday, September 25, 2025
HomeLanguagesPHP | SplFileObject setMaxLineLen() Function

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:




<?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());
  
?>


Output:

int(0) int(20)

Program 2:




<?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>";
    }
?>


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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32319 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6682 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6753 POSTS0 COMMENTS
Umr Jansen
6761 POSTS0 COMMENTS