: This article mainly introduces PHP file writing. For more information about PHP tutorials, see. The file we want to operate is demo.txt.
One way is
$ File = fopen('demo.txt ', 'A ');
$ Content = 'xxxxxxxx ';
Fwrite ($ file, $ content );
Fclose ($ file );
Sometimes file writing is frequent to prevent writing failure. you can use
Flock ($ file, LOCK_EX );
Flock ($ file, LOCK_UN );
Another method
Use file_put_contents ();
If(file_exists('demo.txt ')){
$ Str = 'xxxxx ';
$ Fp = 'deno.txt ';
$ Fcontent = $ str. "\ r \ n ";
File_put_contents ($ fp, $ fcontent, FILE_APPEND | LOCK_EX );
} Else {
Echo 'The file does not exist ';
}
Note that the FILE path to be written is an absolute path, which can be obtained using _ FILE _.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces php file writing, including the content, hope to be helpful to friends who are interested in PHP tutorials.