How can the file_put_contents function be used to append data to a text file in PHP?
To append data to a text file using the file_put_contents function in PHP, you can pass the FILE_APPEND flag as the third parameter. This flag tells the function to append the data to the end of the file instead of overwriting it.
$data = "New data to append to the file.";
file_put_contents('file.txt', $data, FILE_APPEND);
Keywords
Related Questions
- What are the best practices for initializing variables in PHP, especially when it comes to arrays and multidimensional arrays?
- In PHP, what considerations should be taken into account when calculating dates based on user input for duration in weeks?
- What are the security implications of not properly sanitizing input data from forms in PHP applications?