To append content to an existing file in PHP, you can use the built-in fwrite()
function with the FILE_APPEND
flag set. Here is an example:
main.php251 chars12 lines
In the code above, we first obtain a file handle by opening the file in append mode using the fopen()
function. We then use the fwrite()
function to write the content to the file. The FILE_APPEND
flag ensures that the content is appended to the existing file instead of overwriting it. Finally, we close the file handle using the fclose()
function.
Note that if the file doesn't exist already, it will be created automatically in append mode.
gistlibby LogSnag