How to write into a file in PHP?

You can use a higher-level function like:

file_put_contents($filename, $content);

which is identical to calling fopen(), fwrite(), and fclose() successively to write data to a file.

Docs: file_put_contents

Leave a Comment