There are many times you need to write text to a file. Unfortunately when you search google you usually find examples are that use fwrite, fopen, etc.. They are fine grained sure, but most of the time you only need quick and dirty file writing. There is a built in
PHP function that lets you write to a file in just one line:
Code:
file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
The $file variable is the complete path and file name to the file you want to write to, example: /foo/bar/file.txt. The $data variable is what you want written. The last section is optional. It tells
PHP to append to the file rather than overwrite which it does by default. LOCK_EX just exclusively locks the file.
Enjoy! Less code is more!