spl之文件处理
spl是php标准库的缩写
spl文件处理类库: SplFileInfo //是一个类用以获取文件的各种信息SplFileInfo的所有方法如下
方法名 - --- 说明
2. getATime( ) : --- Gets last access time of the file
3. getBasename( ) : --- Gets the base name of the file
4. getCTime( ) : --- 获取文件 inode 修改时间
5. getExtension( ) : --- Gets the file extension
6. getFileInfo( ) : --- Gets an SplFileInfo object for the file
7. getFilename( ) : --- Gets the filename
8. getGroup( ) : --- Gets the file group
9. getInode( ) : --- Gets the inode for the file
10. getLinkTarget( ) : --- Gets the target of a link
11. getMTime( ) : --- Gets the last modified time
12. getOwner( ) : --- Gets the owner of the file
13. getPath( ) : --- Gets the path without filename
14. getPathInfo( ) : --- Gets an SplFileInfo object for the path
15. getPathname( ) : --- Gets the path to the file
16. getPerms( ) : --- Gets file permissions
17. getRealPath( ) : --- Gets absolute path to file
18. getSize( ) : --- Gets file size
19. getType( ) : --- Gets file type
20. isDir( ) : --- Tells if the file is a directory
21. isExecutable( ) : --- Tells if the file is executable
22. isFile( ) : --- Tells if the object references a regular file
23. isLink( ) : --- Tells if the file is a link
24. isReadable( ) : --- Tells if file is readable
25. isWritable( ) : --- Tells if the entry is writable
26. openFile( ) : --- Gets an SplFileObject object for the file
27. setFileClass( ) : --- Sets the class used with openFile
28. setInfoClass( ) : --- Sets the class used with getFileInfo and getPathInfo
29. __toString( ) : --- Returns the path to the file as a string
如获取index.php的相关信息 的代码:
<?php
/*
*author:稻草人
*email:2282152858@qq.com
*cnblogs: http://cnblogs.com/scarecrowlxb
*create time :2017/3/11 23:14
*/
//获取文件信息
$file = new SplFileInfo("./index.php");
echo '创建时间:'.$file->getCTime().PHP_EOL;
echo '修改时间:'.$file->getMTime().PHP_EOL;
echo '文件大小:'.$file->getSize().PHP_EOL;
echo '文件名:'.$file->getFileName().PHP_EOL; //读取文件内容
$fileobj = $file->openFile("r");
while($fileobj->valid()){
//valid 是当读取到的内容无效时返回false
echo $fileobj->fgets();
}
具体见php参考手册中 函数参考->其他基本扩展->spl->文件处理
还有两个类:SplFileObject 和SplTempFileObject
SplFileObject 类继承了SplFileInfo 并实现文件的遍历查找操作
SplTempFileObject类继承了SplFileObject用于对临时文件操作
spl之文件处理的更多相关文章
- spl处理文件(文件详细信息、文件遍历、查询指定行、写入CSV文件)
<?php /** * 文件操作 */ //常用操作 $file = new SplFileInfo('D:/workspace/xlyy/spl/test.txt'); $file_info ...
- PHP高级编程SPL
这几天,我在学习PHP语言中的SPL. 这个东西应该属于PHP中的高级内容,看上去非常复杂,可是非常实用,所以我做了长篇笔记.不然记不住,以后要用的时候,还是要从头学起. 因为这是供自己參考的笔记,不 ...
- u-boot的SPL源码流程分析
上次梳理了一下SPL的基本概念和代码总体思路,这次就针对代码跑的流程做个梳理.SPL中,入口在u-boot-spl.lds中 ENTRY(_start) SECTIONS { .text : { __ ...
- U-boot中SPL功能和源码流程分析
在U-boot目录下,有个比较重要的目录就是SPL的,SPL到底是什么呢?为什么要用它呢? SPL(Secondary programloader)是uboot第一阶段执行的代码.主要负责搬移uboo ...
- php spl标准库简介(SPL是Standard PHP Library(PHP标准库)(直接看代码实例,特别方便)
php spl标准库简介(SPL是Standard PHP Library(PHP标准库)(直接看代码实例,特别方便) 一.总结 直接看代码实例,特别方便易懂 thinkphp控制器利眠宁不支持(说明 ...
- PHP 文件操作的各种姿势
使用 SPL 库 SPL 是 PHP 标准库,用于解决典型问题的一组接口与类的集合. 迭代器 FilesystemIterator 官方文档:http://php.net/manual/zh/clas ...
- SPL常用函数
使用SPL_AUTOLOAD_REGISTER装载类 <?php /** * libs/Test.class.php */ class Test { function __construct() ...
- VIM7.3中文手册
INDEX *index.txt* For Vim version 7.3. 最近更新: 2010年7月 VIM 参考手册 by Bram Moolenaar 译者: Willis h ...
- sphinx ---rotate 运行机制
如果sphinx在运行中,要indexer时,需要加上--rotate参数,这样索引完就直接生效了. 原因是sphinx的searchd在启动时会创建一个 .spl 锁文件,并在关闭时会删除它.在in ...
随机推荐
- C标准I/O建立一个文件仓库
实现了 增删改查 创建了一个结构体 保存 num name cout price 代码 #include<stdio.h>#include<string.h>#include& ...
- Failed to register Grid Infrastructure type ora.mdns.type
安装11g的集群软件的时候,在最后运行root.sh脚本时候,没有执行成功,最后提示如下错误: [root@r2 ~]# /u01/app/11.2.0/grid_1/root.sh Performi ...
- 游戏开发之在UE4中编写C++代码控制角色
当你运行我们上次做完的项目,你可能会意识到我们移动的摄像机还是默认的那个摄像机,这个默认的摄像机可以自由飞翔.这一节,我们要使得开始的角色是我们的一个Avatar类的实例对象,并且使用键盘控制我们的角 ...
- Microsoft IoT Starter Kit 开发初体验-反馈控制与数据存储
在上一篇文章<Microsoft IoT Starter Kit 开发初体验>中,讲述了微软中国发布的Microsoft IoT Starter Kit所包含的硬件介绍.开发环境搭建.硬件 ...
- 选择法排序 vb.net
Imports System.ThreadingModule Module1 Sub Main() 'test code 'Dim a, b As Integer ...
- Java自然语言处理NLP工具包
1. Java自然语言处理 LingPipe LingPipe是一个自然语言处理的Java开源工具包.LingPipe目前已有很丰富的功能,包括主题分类(Top Classification).命名实 ...
- POJ1144(割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12551 Accepted: 5771 Descript ...
- 【python基础】 Tkinter小构件之canvas 画布
[python之tkinter画布] 要画布就要使用tkinter的小构件,canvas(结构化的图形,用于绘制图形,创建图形编辑器以及实现自定制的小构件类) 我们先使用create_rectangl ...
- 如何给 UILable 添加横线
类似淘宝上的原价现价,原价上一般都会有一条横线,这种效果怎么实现呢?其实相当的简单,我们只需要重写自定义的lable的 - (void)drawRect:(CGRect)rect 方法就行了. 具体实 ...
- 性能秒杀log4net的NLogger日志组件(附测试代码与NLogger源码)
NLogger特性: 一:不依赖于第三方插件和支持.net2.0 二:支持多线程高并发 三:读写双缓冲对列 四:自定义日志缓冲大小 五:支持即时触发刷盘机制 六:先按日期再按文件大小滚动Rolling ...