PHP Learning Notes-Advanced tutorials-read files, create files, write files _php tutorial

Source: Internet
Author: User
Tags fread readfile

PHP Learning Notes-Advanced tutorials-read files, create files, write files


Open file: Fopen:fopen (Filename,mode);//fopen ("Test.txt", "R"), open mode: R read-only open, the file pointer to the file header r+ read-write mode open, the file pointer to the file header W write method, point to the file header, If it does not exist then try to create a w+ read-write mode, point to the file header, if it does not exist, try to create a write mode open, point to the end of the file, if it does not exist, try to create a + read-write mode open, point to the end of the file, and attempt to create read file if it does not
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 file is opened that does not exist, this function creates a file that the Jiading file is opened for writing (W) or added (a).
Mode Description
R Open the file as read-only. The file pointer starts 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 starts at the beginning of the file.
A Open the file as write-only. The existing data in the file is retained. The file pointer starts at the end of the file. Creates a new file if the file does not exist.
X Create a new file for write-only. Returns FALSE and an error if the file already exists.
r+ Open the file as read/write, and the file pointer starts 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 starts at the beginning of the file.
A + Open the file for read/write. The data already in the file will be retained. 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 an 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, specifies the number of bytes to read. The default is 1024 bytes.

Reads a row from the file pointed to by the files and returns a string up to length-1 bytes. Stop after encountering a newline character (included in the return value), EOF, or having read length -1 bytes (see first). If lengthis not specified, the default is 1 K, or 1024 bytes.

If it fails, it returns false.

 
  
FGETC (): reads a single character
Fclose (Resource)//close an open file resource unlink (file)//delete a file
Feof (): Check whether the end has been reached. Useful for traversing data of unknown length.
 
  ";} Fclose ($myfile);? >

FileSize (filename): filename is a file name and is a string type. The result of this function is cached, and the Clearstatcache () is cleared to clear the cache. FileType ();

http://www.bkjia.com/PHPjc/851377.html www.bkjia.com true http://www.bkjia.com/PHPjc/851377.html techarticle PHP Learning Notes-Advanced tutorials-read files, create files, write files to open files: Fopen:fopen (Filename,mode),//fopen ("Test.txt", "R"), open mode: R read-only type ...

  • Related Article

    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.