PHP编程文件处理赏罚类SplFileObject和SplFileInfo用法实例说明
发布时间:2021-01-25 19:49:44 所属栏目:编程 来源:网络整理
导读:本篇章节讲授PHP编程文件处理赏罚类SplFileObject和SplFileInfo用法。供各人参考研究详细如下: php对付大文件的处理赏罚除了用以下要领外还可以直接挪用linux呼吁 文件处理赏罚类: 行使要领: fscanf("%s %s %s")) { list ($name,$profession,$countrycode)
本篇章节讲授PHP编程文件处理赏罚类SplFileObject和SplFileInfo用法。分享给各人供各人参考,详细如下: php对付大文件的处理赏罚除了用以下要领外还可以直接挪用linux呼吁 文件处理赏罚类: 行使要领: fscanf("%s %s %s")) {
list ($name,$profession,$countrycode) = $userinfo;
// Do something with $name $profession $countrycode
}*/
public int fseek ( int $offset [,int $whence = SEEK_SET ] ) //按字节移动文件指针位置,
/*SEEK_SET 配置文件指针到指定字节位置(默以为该模式).
SEEK_CUR 配置文件指针到当前位置加上指定字节位置.
SEEK_END 配置文件指针到文件末端加上指定字节位置(此时字节常常为负值).
public array fstat ( void ) //获取文件信息,以数组情势返回*/
/*
数字下标 关联键名(自 PHP 4.0.6) 声名
0 dev device number - 装备名
1 ino inode number - inode 号码
2 mode inode protection mode - inode 掩护模式
3 nlink number of links - 被毗连数量
4 uid userid of owner - 全部者的用户 id
5 gid groupid of owner- 全部者的组 id
6 rdev device type,if inode device * - 装备范例,假如是 inode 装备的话
7 size size in bytes - 文件巨细的字节数
8 atime time of last access (unix timestamp) - 前次会见时刻(Unix 时刻戳)
9 mtime time of last modification (unix timestamp) - 前次修改时刻(Unix 时刻戳)
10 ctime time of last change (unix timestamp) - 前次改变时刻(Unix 时刻戳)
11 blksize blocksize of filesystem IO * - 文件体系 IO 的块巨细
12 blocks number of blocks allocated - 所占有块的数量* Windows 下老是 0。
* - 仅在支持 st_blksize 范例的体系下有用。其余体系(如 Windows)返回 -1。 */
public int ftell ( void ) //返回当前文件位置,文件指针位置
public bool ftruncate ( int $size ) //将文件截断到指定的长度,若长度大于文件长度用空补齐(文件打开要领对其有影响)
public int fwrite ( string $str [,int $length ] ) //将$str字符串写入文件,只写$length长度。放回写入字节数或null
public array getCsvControl ( void ) //Gets the delimiter and enclosure character used for parsing CSV fields.
public int getFlags ( void ) //Gets the flags set for an instance of SplFileObject as an integer.
public int getMaxLineLen ( void ) //返回一行读取的最大字节数(在已配置的条件下),若未配置,默以为0
public int key ( void ) //获取当前行号。
public void next ( void ) //移动到下一行
public void rewind ( void ) //返回到第一行
public void seek ( int $line_pos ) //定位到文件指定行
public void setCsvControl ([ string $delimiter = ",string $escape = "" ]]] )
public void setFlags ( int $flags )
public void setMaxLineLen ( int $max_len ) //配置文件读取一行的最大字节数,若文件每行有10个字符,但配置最大读取为
public bool valid ( void ) //搜查是否达到文件底部,未达到底部返回 TRUE ,抵达返回false.
}
用法: eof()) {
echo $file->current();
$file->next();
}
//封锁文件工具
$file = null;
常用文件处理赏罚要领: seek($startLine - 1); // 转到第N行,seek要领参数从0开始计数 for ($i = 0; $i <= $count; ++$i) { $content[] = $fp->current(); // current()获取当前行内容 $fp->next(); // 下一行 if($fp->eof()) { array_pop($content); break; } } return array_filter($content); // array_filter过滤:false,null,'' } /** * 获取文章最后一行内容 * @param string $res 文件路径/名 */ function get_last_line($res) { $fp = fopen($res,'r'); if (false == $fp) { return 'error'; } fseek($fp,-1,SEEK_END); $s = ''; while(($c = fgetc($fp)) !== false) { if($c == "n" && $s) break; $s = $c . $s; fseek($fp,-2,SEEK_CUR); } fclose($fp); return $s; }更多关于PHP相干内容感乐趣的读者可查察本站专题:《》、《》、《》、《》、《》、《》及《》 但愿本文所述对各人PHP措施计划有所辅佐。 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐
热点阅读