Becky Becky - 7 months ago 33
PHP Question

Add data to text with print_r()

I have a text file and each time a visitor access this page I am doing a print_r() to it.

How can I use print_r() to add data to my

text file ? Currently the text is overwritten and stores only last print_r().

$output = print_r($data, true);
file_put_contents('file.txt', $output);


You can use the FILE_APPEND flag:

file_put_contents('file.txt', $output, FILE_APPEND);

FILE_APPEND If file filename already exists, append the data to the file instead of overwriting it.