ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# [SplFileObject](https://www.php.net/manual/zh/class.splfileobject.php) >[info] SplFileObject类为文件提供了一个面向对象接口. ``` SplFileObject extends SplFileInfo implements RecursiveIterator , SeekableIterator { /* 常量 */ const integer DROP_NEW_LINE = 1 ;//在行尾删除换行符 const integer READ_AHEAD = 2 ; //rewind/nextd的方式读取 const integer SKIP_EMPTY = 4 ; //跳过文件中的空行。这需要启用READ_AHEAD标志,才能按预期工作 const integer READ_CSV = 8 ; //将行读取为CSV行。 /* 方法 */ public eof ( void ) : bool //到达文件结尾 public fflush ( void ) : bool //将输出刷新到文件 public fgetc ( void ) : string //从文件中获取字符 public fgetcsv ([ string $delimiter = "," [, string $enclosure = "\"" [, string $escape = "\\" ]]] ) : array //从文件中获取行并解析为CSV字段 public fgets ( void ) : string //从文件中获取行 public fgetss ([ string $allowable_tags ] ) : string //从文件中获取行并剥离HTML标记 public flock ( int $operation [, int &$wouldblock ] ) : bool //便携式文件锁定 public fpassthru ( void ) : int //输出文件指针上的所有剩余数据 public fputcsv ( array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape = "\\" ]]] ) : int //将字段数组写为CSV行 public fread ( int $length ) : string //从文件中读取 public fscanf ( string $format [, mixed &$... ] ) : mixed //根据格式从文件中解析输入 public fseek ( int $offset [, int $whence = SEEK_SET ] ) : int //寻求一个位置 public fstat ( void ) : array //获取有关该文件的信息 public ftell ( void ) : int //返回当前文件位置 public ftruncate ( int $size ) : bool //将文件截断为给定长度 public fwrite ( string $str [, int $length ] ) : int //写入文件 public getCsvControl ( void ) : array //获取CSV的分隔符,机箱和转义字符 public getCurrentLine ( void ) : string //SplFileObject :: fgets的别名 public getFlags ( void ) : int //获取SplFileObject的标志 public getMaxLineLen ( void ) : int //获得最大线长 public setCsvControl ([ string $delimiter = "," [, string $enclosure = "\"" [, string $escape = "\\" ]]] ) : void //获取CSV的分隔符,机箱和转义字符 public setFlags ( int $flags ) : void //设置SplFileObject的标志 public setMaxLineLen ( int $max_len ) : void //设置最大行长度 //RecursiveIterator public getChildren ( void ) : void //返回当前条目的迭代器(No purpose?) public hasChildren ( void ) : bool //返回是否可以为当前条目创建迭代器(SplFileObject没有子级) //SeekableIterator public seek ( int $line_pos ) : void //RecursiveIterator与SeekableIterator public current ( void ) : string|array //检索当前文件行 public key ( void ) : int public next ( void ) : void public rewind ( void ) : void public valid ( void ) : bool /* 继承的方法 */ public __construct ( string $file_name ) public getATime ( void ) : int //获取文件的上次访问时间 public getBasename ([ string $suffix ] ) : string //获取文件的基本名称 public getCTime ( void ) : int //获取文件 inode 修改时间 public getExtension ( void ) : string //获取文件扩展名 public getFileInfo ([ string $class_name ] ) : SplFileInfo //获取文件的SplFileInfo对象 public getFilename ( void ) : string //获取文件名 public getGroup ( void ) : int //获取文件组 public getInode ( void ) : int //获取文件的inode public getLinkTarget ( void ) : string //获取链接的目标 public getMTime ( void ) : int //获取上次修改时间 public getOwner ( void ) : int //获取文件的所有者 public getPath ( void ) : string //获取没有文件名的路径 public getPathInfo ([ string $class_name ] ) : SplFileInfo //获取路径的SplFileInfo对象 public getPathname ( void ) : string //获取文件的路径 public getPerms ( void ) : int //获取文件权限 public getRealPath ( void ) : string //获取文件的绝对路径 public getSize ( void ) : int //获取文件大小 public getType ( void ) : string //获取文件类型 public isDir ( void ) : bool //判断文件是否是目录 public isExecutable ( void ) : bool //判断文件是否可执行 public isFile ( void ) : bool //判断对象是否引用了常规文件 public isLink ( void ) : bool //判断文件是否为链接 public isReadable ( void ) : bool //判断文件是否可读 public isWritable ( void ) : bool //判断条目是否可写 public openFile ([ string $open_mode = "r" [, bool $use_include_path = FALSE [, resource $context = NULL ]]] ) : SplFileObject //获取文件的SplFileObject对象 public setFileClass ([ string $class_name = "SplFileObject" ] ) : void //设置与SplFileInfo :: openFile一起使用的类 public setInfoClass ([ string $class_name = "SplFileInfo" ] ) : void //设置与SplFileInfo :: getFileInfo和SplFileInfo :: getPathInfo一起使用的类 public __toString ( void ) : string //以字符串形式返回文件的路径 SplFileObject :: fgets的别名 } ```