The SplFileObject class
(PHP 5 >= 5.1.0, PHP 7)
Introduction
The SplFileObject class offers an object oriented interface for a file.
Class synopsis
$filename
[, string $open_mode
= "r"
[, bool $use_include_path
= FALSE
[, resource $context
]]] )$delimiter
= ","
[, string $enclosure
= "\""
[, string $escape
= "\\"
]]] ) : array$fields
[, string $delimiter
= ","
[, string $enclosure
= '"'
[, string $escape
= "\\"
]]] ) : int$delimiter
= ","
[, string $enclosure
= "\""
[, string $escape
= "\\"
]]] ) : void$open_mode
= "r"
[, bool $use_include_path
= FALSE
[, resource $context
= NULL
]]] ) : SplFileObjectPredefined Constants
SplFileObject::DROP_NEW_LINE
-
Drop newlines at the end of a line.
SplFileObject::READ_AHEAD
-
Read on rewind/next.
SplFileObject::SKIP_EMPTY
-
Skips empty lines in the file. This requires the
READ_AHEAD
flag be enabled, to work as expected. SplFileObject::READ_CSV
-
Read lines as CSV rows.
Table of Contents
- SplFileObject::__construct — Construct a new file object
- SplFileObject::current — Retrieve current line of file
- SplFileObject::eof — Reached end of file
- SplFileObject::fflush — Flushes the output to the file
- SplFileObject::fgetc — Gets character from file
- SplFileObject::fgetcsv — Gets line from file and parse as CSV fields
- SplFileObject::fgets — Gets line from file
- SplFileObject::fgetss — Gets line from file and strip HTML tags
- SplFileObject::flock — Portable file locking
- SplFileObject::fpassthru — Output all remaining data on a file pointer
- SplFileObject::fputcsv — Write a field array as a CSV line
- SplFileObject::fread — Read from file
- SplFileObject::fscanf — Parses input from file according to a format
- SplFileObject::fseek — Seek to a position
- SplFileObject::fstat — Gets information about the file
- SplFileObject::ftell — Return current file position
- SplFileObject::ftruncate — Truncates the file to a given length
- SplFileObject::fwrite — Write to file
- SplFileObject::getChildren — No purpose
- SplFileObject::getCsvControl — Get the delimiter, enclosure and escape character for CSV
- SplFileObject::getCurrentLine — Alias of SplFileObject::fgets
- SplFileObject::getFlags — Gets flags for the SplFileObject
- SplFileObject::getMaxLineLen — Get maximum line length
- SplFileObject::hasChildren — SplFileObject does not have children
- SplFileObject::key — Get line number
- SplFileObject::next — Read next line
- SplFileObject::rewind — Rewind the file to the first line
- SplFileObject::seek — Seek to specified line
- SplFileObject::setCsvControl — Set the delimiter, enclosure and escape character for CSV
- SplFileObject::setFlags — Sets flags for the SplFileObject
- SplFileObject::setMaxLineLen — Set maximum line length
- SplFileObject::__toString — Alias of SplFileObject::fgets
- SplFileObject::valid — Not at EOF
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.splfileobject.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.