PHP 8.2.0 Alpha 2 available for testing


(PHP 5 >= 5.1.0, PHP 7, PHP 8)

SplFileObject::setMaxLineLenSet maximum line length


public SplFileObject::setMaxLineLen(int $maxLength): void

Sets the maximum length of a line to be read.



The maximum length of a line.

Return Values

No value is returned.


Throws DomainException when maxLength is less than zero.


Example #1 SplFileObject::setMaxLineLen() example

= new SplFileObject("lipsum.txt");
foreach (
$file as $line) {
$line "\n";

Contents of lipsum.txt

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Duis nec sapien felis, ac sodales nisl.
Nulla vitae magna vitae purus aliquet consequat.

The above example will output something similar to:

Lorem ipsum dolor s
it amet, consectetu
r adipiscing elit.

Duis nec sapien fel
is, ac sodales nisl

Nulla vitae magna v
itae purus aliquet 

See Also

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top