SplFileObject
class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator (View source)
The SplFileObject class offers an object oriented interface for a file.
Constants
DROP_NEW_LINE |
Drop newlines at the end of a line. |
READ_AHEAD |
Read on rewind/next. |
SKIP_EMPTY |
Skip empty lines in the file. This requires the {READ_AHEAD} flag to work as expected. |
READ_CSV |
Read lines as CSV rows. |
Methods
Construct a new file object.
Gets an SplFileInfo object for the path
Gets an SplFileObject object for the file
Sets the class name used with SplFileInfo::openFile
Sets the class used with getFileInfo and getPathInfo
Alias of SplFileObject::current
Rewind the file to the first line
Reached end of file
Not at EOF
Gets line from file
Read from file
Gets line from file and parse as CSV fields
Write a field array as a CSV line
Set the delimiter and enclosure character for CSV
Get the delimiter and enclosure character for CSV
Portable file locking
Flushes the output to the file
Return current file position
Seek to a position
Gets character from file
Output all remaining data on a file pointer
Gets line from file and strip HTML tags
Parses input from file according to a format
Write to file
Gets information about the file
Truncates the file to a given length
Retrieve current line of file
Get line number
Read next line
Sets flags for the SplFileObject
Gets flags for the SplFileObject
Set maximum line length
Get maximum line length
SplFileObject does not have children
No purpose
Seek to specified line
Alias of SplFileObject::fgets
Details
__construct(string $filename, string $mode = 'r', bool $useIncludePath = false, resource $context = null)
Construct a new file object.
string
getPath()
Gets the path without filename
string
getFilename()
Gets the filename
string
getExtension()
Gets the file extension
string
getBasename(string $suffix = '')
Gets the base name of the file
string
getPathname()
Gets the path to the file
int|false
getPerms()
Gets file permissions
int|false
getInode()
Gets the inode for the file
int|false
getSize()
Gets file size
int|false
getOwner()
Gets the owner of the file
int|false
getGroup()
Gets the file group
int|false
getATime()
Gets last access time of the file
int|false
getMTime()
Gets the last modified time
int|false
getCTime()
Gets the inode change time
string|false
getType()
Gets file type
bool
isWritable()
Tells if the entry is writable
bool
isReadable()
Tells if file is readable
bool
isExecutable()
Tells if the file is executable
bool
isFile()
Tells if the object references a regular file
bool
isDir()
Tells if the file is a directory
bool
isLink()
Tells if the file is a link
string|false
getLinkTarget()
Gets the target of a link
string|false
getRealPath()
Gets absolute path to file
SplFileInfo
getFileInfo(T> $class = null)
Gets an SplFileInfo object for the file
SplFileInfo|null
getPathInfo(T> $class = null)
Gets an SplFileInfo object for the path
SplFileObject
openFile(string $mode = 'r', bool $useIncludePath = false, resource $context = null)
Gets an SplFileObject object for the file
void
setFileClass(T> $class = SplFileObject::class)
Sets the class name used with SplFileInfo::openFile
void
setInfoClass(T> $class = SplFileInfo::class)
Sets the class used with getFileInfo and getPathInfo
string
__toString()
Alias of SplFileObject::current
final void
_bad_state_ex()
No description
__wakeup()
No description
array
__debugInfo()
No description
void
rewind()
Rewind the file to the first line
bool
eof()
Reached end of file
bool
valid()
Not at EOF
string
fgets()
Gets line from file
string|false
fread(int $length)
Read from file
array|false|null
fgetcsv(string $separator = ",", string $enclosure = "\"", string $escape = "\\")
Gets line from file and parse as CSV fields
int|false
fputcsv(array $fields, string $separator = ',', string $enclosure = '"', string $escape = "\\", string $eol = PHP_EOL)
Write a field array as a CSV line
void
setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\")
Set the delimiter and enclosure character for CSV
array
getCsvControl()
Get the delimiter and enclosure character for CSV
bool
flock(int $operation, int $wouldBlock = null)
Portable file locking
bool
fflush()
Flushes the output to the file
int|false
ftell()
Return current file position
int
fseek(int $offset, int $whence = SEEK_SET)
Seek to a position
string|false
fgetc()
Gets character from file
int
fpassthru()
Output all remaining data on a file pointer
string|false
fgetss(string $allowable_tags = null)
Gets line from file and strip HTML tags
array|int|null
fscanf(string $format, mixed ...$vars)
Parses input from file according to a format
int|false
fwrite(string $data, int $length = 0)
Write to file
array
fstat()
Gets information about the file
bool
ftruncate(int $size)
Truncates the file to a given length
mixed
current()
Retrieve current line of file
mixed
key()
Get line number
void
next()
Read next line
void
setFlags(int $flags)
Sets flags for the SplFileObject
int
getFlags()
Gets flags for the SplFileObject
void
setMaxLineLen(int $maxLength)
Set maximum line length
int
getMaxLineLen()
Get maximum line length
bool
hasChildren()
SplFileObject does not have children
RecursiveIterator|null
getChildren()
No purpose
void
seek(int $line)
Seek to specified line
string
getCurrentLine()
Alias of SplFileObject::fgets