<?PHP$FR=fopen("./data/test.txt", ' a '); //fopen (position, open mode) if(!$FR) { Echo"Error"; Exit; } fwrite($FR, "line1". " \ n "); //Insert Content fwrite($FR, "Line2". " \ n "); fwrite($FR, "Line3". " \ n "); fclose($FR); //Close Document?>
About open Mode
R read-only-read mode, open file, start reading from file header
r+ read-write to open the file, read and write from the file header
W write-write to open the file, while emptying the contents of the file, the file pointer point to the beginning of the file. If the file already exists, the existing content of the file is deleted, and if the file does not exist, the file is created
w+ can open the file in a readable and writable manner while emptying the contents of the file and pointing the file pointer at the beginning of the file. If the file does not exist, the file is created
A append opens the file in write-only mode, pointing the file pointer at the end of the file. If the file does not exist, the file is created
A + is followed by a readable and writable way to open the file, pointing the file pointer at the end of the file. If the file does not exist, the file is created
b binary is used to connect to other modes. It is recommended to use this option for a greater degree of portability
PHP txt operation, adding the class capacity