Are there any potential pitfalls to be aware of when using file_put_contents in PHP?

One potential pitfall when using file_put_contents in PHP is that it will overwrite the contents of the file if it already exists. To avoid this, you can use the FILE_APPEND flag to append the new content to the existing file instead.

// Use FILE_APPEND flag to append content to file instead of overwriting
$file = 'example.txt';
$content = 'New content to add to file';

file_put_contents($file, $content, FILE_APPEND);