write output of print_r in a txt file. PHP

php

Solution

`print_r()` has a second parameters that if passed as `TRUE` returns the output as a string.

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

You could even cosinder using `var_export` function, as it provides better information about data types. From `print_r` you can't tell if the variable is NULL of FALSE, but `var_export` lets use see exactly the data type of a variable.

Problem

Possible Duplicate: Print array to a file How can I write the ouput (for example when I use an array), in a file?, I was trying with this: ``` ... print_r($this->show_status_redis_server()); $status_redis = ob_get_contents(); fwrite($file, $status_redis); ... ```

Original source

Related problems