array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'class.splfileobject.php', 1 => 'SplFileObject', ), 'up' => array ( 0 => 'spl.files.php', 1 => '文件处理', ), 'prev' => array ( 0 => 'splfileinfo.tostring.php', 1 => 'SplFileInfo::__toString', ), 'next' => array ( 0 => 'splfileobject.construct.php', 1 => 'SplFileObject::__construct', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/spl/splfileobject.xml', ), 'extra_header_links' => array ( 'rel' => 'alternate', 'href' => '/manual/en/feeds/class.splfileobject.atom', 'type' => 'application/atom+xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
SplFileObject 类为文件提供了一个面向对象接口。
$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 方法时,从文件中读取一行数据。
SplFileObject::SKIP_EMPTY
跳过文件中的空白行。这需要启用
READ_AHEAD
标志,以达到预期的效果。
SplFileObject::READ_CSV
以 CSV 行的形式读取。