国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

PHP_ SPL標準庫之文件操作

2019-11-02 15:22:23
字體:
來源:轉載
供稿:網友

   這篇文章主要介紹了PHP SPL標準庫之文件操作(SplFileInfo和SplFileObject)實例,本文講解SplFileInfo用來獲取文件詳細信息、SplFileObject遍歷、查找指定行、寫入csv文件等內容,需要的朋友可以參考下

  PHP SPL中提供了SplFileInfo和SplFileObject兩個類來處理文件操作。

  SplFileInfo用來獲取文件詳細信息:

   代碼如下:

  $file = new SplFileInfo('foo-bar.txt');

  print_r(array(

  'getATime' => $

qq超拽網名[www.la240.com/html2017/1/4/]
file->getATime(), //最后訪問時間

  'getBasename' => $file->getBasename(), //獲取無路徑的basename

  'getCTime' => $file->getCTime(), //獲取inode修改時間

  'getExtension' => $file->getExtension(), //文件擴展名

  'getFilename' => $file->getFilename(), //獲取文件名

  'getGroup' => $file->getGroup(), //獲取文件組

  'getInode' => $file->getInode(), //獲取文件inode

  'getLinkTarget' => $file->getLinkTarget(), //獲取文件鏈接目標文件

  'getMTime' => $file->getMTime(), //獲取最后修改時間

  'getOwner' => $file->getOwner(), //文件擁有者

  'getPath' => $file->getPath(), //不帶文件名的文件路徑

  'getPathInfo' => $file->getPathInfo(), //上級路徑的SplFileInfo對象

  'getPathname' => $file->getPathname(), //全路徑

  'getPerms' => $file->getPerms(), //文件權限

  'getRealPath' => $file->getRealPath(), //文件絕對路徑

  'getSize' => $file->getSize(),//文件大小,單位字節

  'getType' => $file->getType(),//文件類型 file dir link

  'isDir' => $file->isDir(), //是否是目錄

  'isFile' => $file->isFile(), //是否是文件

  'isLink' => $file->isLink(), //是否是快捷鏈接

  'isExecutable' => $file->isExecutable(), //是否可執行

  'isReadable' => $file->isReadable(), //是否可讀

  'isWritable' => $file->isWritable(), //是否可寫

  ));

  SplFileObject繼承SplFileInfo并實現RecursiveIterator , SeekableIterator接口 ,用于對文件遍歷、查找、操作

  遍歷:

   代碼如下:

  try {

  foreach(new SplFileObject('foo-bar.txt') as $line) {

  echo $line;

  }

  } catch (Exception $e) {

  echo $e->getMessage();

  }

  查找指定行:

     代碼如下:

  try {

  $file = new SplFileObject('foo-bar.txt');

  $file->seek(2);

  echo $file->current();

  } catch (Exception $e) {

  echo $e->getMessage();

  }

  寫入csv文件:

  代碼如下:

  $list = array (

  array( 'aaa' , 'bbb' , 'ccc' , 'dddd' ),

  array( '123' , '456' , '7891' ),

  array( '"aaa"' , '"bbb"' )

  );

  $file = new SplFileObject ( 'file.csv' , 'w' );

  foreach ( $list as $fields ) {

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀仁县| 页游| 建平县| 武宁县| 青冈县| 开江县| 沂南县| 精河县| 兴安县| 永城市| 昌吉市| 阳朔县| 福建省| 山东省| 乌鲁木齐县| 孙吴县| 邵阳市| 恩平市| 太仆寺旗| 北宁市| 伽师县| 沙田区| 明溪县| 漳州市| 平度市| 平顺县| 外汇| 临潭县| 宝丰县| 凌源市| 三原县| 云霄县| 巴彦县| 犍为县| 临沭县| 奉贤区| 若尔盖县| 清河县| 静乐县| 九龙坡区| 扬中市|