(PHP 5 >= 5.1.0, PHP 7, PHP 8)
SplFileObject 類(lèi)為文件提供了一個(gè)面向對象接口。
$filename
,$mode
= "r",$useIncludePath
= false
,$context
= null
$separator
= ",", string $enclosure
= "\"", string $escape
= "\\"): array|false$fields
,$separator
= ",",$enclosure
= "\"",$escape
= "\\",$eol
= "\n"$separator
= ",", string $enclosure
= "\"", string $escape
= "\\"): void$mode
= "r", bool $useIncludePath
= false
, ?resource $context
= null
): SplFileObjectSplFileObject::DROP_NEW_LINE
刪除行尾的換行符。
SplFileObject::READ_AHEAD
使用 rewind 或 next 方法時(shí),從文件中讀取一行數據。
SplFileObject::SKIP_EMPTY
跳過(guò)文件中的空白行。這需要啟用
READ_AHEAD
標志,以達到預期的效果。
SplFileObject::READ_CSV
以 CSV 行的形式讀取。