SplFileObject 類
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
簡介
SplFileObject 類為檔案提供了一個物件導向介面。
類摘要
/* 常量 */
/* 方法 */
public __construct(
string
string
bool
?resource
)
string
$filename
,string
$mode
= "r",bool
$useIncludePath
= false
,?resource
$context
= null
)
public fgetcsv(string
$separator
= ",", string $enclosure
= "\"", string $escape
= "\\"): array|falsepublic fputcsv(
array
string
string
string
string
): int|false
array
$fields
,string
$separator
= ",",string
$enclosure
= "\"",string
$escape
= "\\",string
$eol
= "\n"): int|false
public setCsvControl(string
$separator
= ",", string $enclosure
= "\"", string $escape
= "\\"): void/* 繼承的方法 */
public SplFileInfo::openFile(string
}$mode
= "r", bool $useIncludePath
= false
, ?resource $context
= null
): SplFileObject預定義常量
SplFileObject::DROP_NEW_LINE
-
刪除行尾的換行符。
SplFileObject::READ_AHEAD
-
使用 rewind 或 next 方法時,從檔案中讀取一行數據。
SplFileObject::SKIP_EMPTY
-
跳過檔案中的空白行。這需要啟用
READ_AHEAD
標誌,以達到預期的效果。 SplFileObject::READ_CSV
-
以 CSV 行的形式讀取。
目錄
- 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