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 ...
随机推荐
- easyui弹出窗关闭前调用确认窗口,先关闭页面后调用弹出窗口
弹出窗关闭的时候提示是否关闭,同时进行一些对应的方法调用, 然而在进行页面关闭调用的时候,往往页面关闭了,才弹出确认对话框, $.messager.confirm和panel的onBeforeClos ...
- 扩展BaseAdapter实现不存储列表项的ListView
下面的实例将会通过扩展BaseAdapter来实现Adapter,扩展BaseAdapter可以取得对Adapter最大的控制权:程序要创建多个列表项,每个列表项的组件都由开发者来决定. 下面的布局文 ...
- log4j.rootLogger详细说明
http://blog.csdn.net/anlina_1984/article/details/5313023
- React Router基础使用
React是个技术栈,单单使用React很难构建复杂的Web应用程序,很多情况下我们需要引入其他相关的技术 React Router是React的路由库,保持相关页面部件与URL间的同步 下面就来简单 ...
- HDU1716(全排列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Jcompress: 一款基于huffman编码和最小堆的压缩、解压缩小程序
前言 最近基于huffman编码和最小堆排序算法实现了一个压缩.解压缩的小程序.其源代码已经上传到github上面: Jcompress下载地址 .在本人的github上面有一个叫Utility的re ...
- 机器学习实战笔记(1)——k-近邻算法
机器学习实战笔记(1) 1. 写在前面 近来感觉机器学习,深度学习神马的是越来越火了,从AlphaGo到Master,所谓的人工智能越来越NB,而我又是一个热爱新潮事物的人,于是也来凑个热闹学习学习. ...
- ios NSString拼接方法总结
NSString* string; // 结果字符串 02 NSString* string1, string2; //已存在的字符串,需要将string1和string2连接起来 03 04 / ...
- 在C语言中以编程的方式获取函数名
仅仅为了获取函数名,就在函数体中嵌入硬编码的字符串,这种方法单调乏味还易导致错误,不如看一下怎样使用新的C99特性,在程序运行时获取函数名吧. 对象反射库.调试工具及代码分析器,经常会需要在运行时访问 ...
- 《JAVASCRIPT高级程序设计》错误处理与调试
一.错误处理 错误处理在程序设计中的重要性是毋庸置疑的,任何有影响力的web应用程序都需要一套完善的错误处理机制.良好的错误机制可以让用户得到提醒,知道发生了什么事. 1.try-catch语句 tr ...