A classe SplFileObject

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

Introdução

A classe SplFileObject oferece uma interface orientada a objetos para um arquivo.

Resumo da classe

class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator {
/* Constantes */
public const int DROP_NEW_LINE;
public const int READ_AHEAD;
public const int SKIP_EMPTY;
public const int READ_CSV;
/* Métodos */
public __construct(
    string $filename,
    string $mode = "r",
    bool $useIncludePath = false,
    ?resource $context = null
)
public eof(): bool
public fflush(): bool
public fgetc(): string|false
public fgetcsv(string $separator = ",", string $enclosure = "\"", string $escape = "\\"): array|false
public fgets(): string
public fgetss(string $allowable_tags = ?): string
public flock(int $operation, int &$wouldBlock = null): bool
public fpassthru(): int
public fputcsv(
    array $fields,
    string $separator = ",",
    string $enclosure = "\"",
    string $escape = "\\",
    string $eol = "\n"
): int|false
public fread(int $length): string|false
public fscanf(string $format, mixed &...$vars): array|int|null
public fseek(int $offset, int $whence = SEEK_SET): int
public fstat(): array
public ftell(): int|false
public ftruncate(int $size): bool
public fwrite(string $data, int $length = 0): int|false
public getChildren(): null
public getFlags(): int
public getMaxLineLen(): int
public hasChildren(): false
public key(): int
public next(): void
public rewind(): void
public seek(int $line): void
public setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\"): void
public setFlags(int $flags): void
public setMaxLineLen(int $maxLength): void
public __toString(): string
public valid(): bool
/* Métodos herdados */
public SplFileInfo::getBasename(string $suffix = ""): string
public SplFileInfo::openFile(string $mode = "r", bool $useIncludePath = false, ?resource $context = null): SplFileObject
public SplFileInfo::setFileClass(string $class = SplFileObject::class): void
public SplFileInfo::setInfoClass(string $class = SplFileInfo::class): void
}

Constantes pré-definidas

SplFileObject::DROP_NEW_LINE

Remove quebras de linha no final de uma linha.

SplFileObject::READ_AHEAD

Lê ao rebobinar/avançar.

SplFileObject::SKIP_EMPTY

Pula linhas vazias no arquivo. Isso requer que a flag READ_AHEAD esteja ativada para funcionar como esperado.

SplFileObject::READ_CSV

Lê linhas como linhas CSV.

Table of Contents