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);
...
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.
print_r($expression [, bool $return = false ])
has optional parameter that identifies you want to return string or echo one.
$str = print_r($desiredVariable, true);
fwrite($handle, $str);
Also I'd use file_put_contents
:
$content = print_r($yourVar, true);
file_put_contents('file.log', $content);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With