PHP Learning Notes-Advanced tutorials-reading files, creating files, writing Files

Source: Internet
Author: User
Tags end fread header readfile resource string
Open file: Fopen:fopen (Filename,mode);//fopen ("Test.txt", "R"); Open mode: R read-only open, point file pointer to file header r+ read-write mode open, point file pointer to file header W Write, point to file header, If it does not exist, try to create a w+ read-write, point to the file header, and if it does not exist, try to create a write-through, point to the end of the file, and if not, try to create a + read-write open, point to the end of the file, and try to create
ReadFile (filename): reads the contents of the file and writes it to the output buffer
 
  
fopen (Filename,mode): Open file, create file
 
  
Fopen is also used to create files, if a nonexistent file is opened, this function creates the file, the Jiading file is opened for writing (W), or an increase (a).
Mode Description
R Open the file as read-only. The file pointer begins at the beginning of the file.
W Open the file as write-only. Delete the contents of the file or create a new file if it does not exist. The file pointer begins at the beginning of the file.
A Open the file as write-only. Existing data in the file will be preserved. The file pointer starts at the end of the file. Create a new file if the file does not exist.
X Create a new file as write-only. Returns false and error if the file already exists.
r+ Opens the file as read/write, and the file pointer begins at the beginning of the file.
w+ Open the file for read/write. Delete the contents of the file or create a new file if it does not exist. The file pointer begins at the beginning of the file.
A + Open the file for read/write. The data already in the file will be preserved. The file pointer starts at the end of the file. Creates a new file if it does not exist.
x+ Create a new file for read/write. Returns false and error if the file already exists.
Fwrite (resources, content)//write file contents
 
  
Fread (): The function reads the open file.
Fread ($myfile, FileSize ("Webdictionary.txt"));

Fget (resource, length)//Get the contents of the file, if the length is 10, you can get 9-bit fgets (): Used to read a single line, fgets (file,lenght), lenght optional, specify the number of bytes to read. The default is 1024 bytes.

Reads a row from the file pointed to by files and returns a string of up to length 1 bytes. Stops when a line break (included in the return value), EOF, or length -1 bytes has been read (see the first case). If lengthis not specified, the default is 1 K, or 1024 bytes.

Returns False if the failure occurs.

 
  
FGETC (): Reading a single character
Fclose (resources)//Close an open file resource unlink (file)//delete a file
Feof (): Check to see if the end has been reached. Useful for traversing data of unknown length.
 
  ";
}
Fclose ($myfile);
? >

FileSize (filename): filename is the filename, is the string type. The results of this function are cached, and the trial Clearstatcache () is cleared to clear the cache. FileType ();

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.