SPL Processing files (file details, file traversal, querying a specified line, writing to a CSV file)

Source: Internet
Author: User
Tags file type file spl

<?PHP/** * File Operation*///Common Operations$file=NewSplfileinfo (' D:/workspace/xlyy/spl/test.txt ');$file _info=Array(    ' Getatime ' =$file->getatime (),//Last access Time' Getbasename ' =$file->getbasename (),//Get file name' Getctime ' =$file->getctime (),//Get inode modification Time' GetExtension ' =$file->getextension (),//file name extension' GetFileName ' =$file->getfilename (),//file name' Getgroup ' =$file->getgroup (),//the group where the file resides' Getinode ' =$file->getinode (),//Get file Inode' Getlinktarget ' =$file->getlinktarget (),//get File link destination file' Getmtime ' =$file->getmtime (),//file Last modified time' GetOwner ' =$file->getowner (),//Get file owner' GetPath ' =$file->getpath (),//get a path without a file name' GetPathInfo ' =$file->getpathinfo (),//ancestor path Splfileinfo object' GetPathName ' =$file->getpathname (),//Full path' Getperms ' =$file->getperms (),//Permissions' Getrealpath ' =$file->getrealpath (),//Absolute Path' GetSize ' =$file->getsize (),//file Size (bytes)' GetType ' =$file-GetType(),//file Type File/dir/link' Isdir ' =$file->isdir (),//whether it is a directory' Isfile ' =$file->isfile (),//whether it is a file' Islink ' =$file->islink (),//whether it is a file' IsExecutable ' =$file->isexecutable (),//whether it can be executed' IsReadable ' =$file->isreadable (),//whether it is readable' IsWritable ' =$file->iswritable (),//whether it can be written);Echo' <pre> ';Print_r($file _info);Echo' </pre> ';Echo' ;//Traversal OperationsTry{    foreach(NewSplfileobject (' Test.txt ') as $line){//iterate through the contents of a file        Echo $line; }}Catch(Exception $e){    Echo $e-getMessage ();}Echo' ;//finds the specified rowTry{    $file=NewSplfileobject (' Test.txt '); $file->seek (2); Echo $file- Current();}Catch(Exception $e){    Echo $e-getMessage ();}//writing to a CSV file$list=Array(    Array(' aaaa ', ' bbbbb ', ' cccccc ', ' ddddddddd '),Array(' 123 ', 456,789),Array(' AA ', ' BB '),);$file=NewSplfileobject (' File.csv ', ' W ');foreach($list  as $fields){    $file->fputcsv ($fields);}

SPL Processing files (file details, file traversal, querying a specified line, writing to a CSV file)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.