August Karlstrom escribió:
Thanks. I still have a problem though. For some reason the output
contains sequences of `\n' instead of newlines.
Example:
error_log(print_r(Array(1, 2, 3), 1));
Output:
[Thu Oct 09 10:06:37 2008] [error] [client 127.0.0.1] Array\n(\n [0]
=1\n [1] =2\n [2] =3\n)\n, referer: ...
error_log() sends errors either to a file or to system logging; the
latter might not support multi-line output. I've tried this code in
Windows XP from command line:
<?php
ini_set('log_errors', 1);
ini_set('error_log', 'error.log');
error_log(print_r(Array(1, 2, 3), 1));
?>
It does save line feeds, but it mixes different line endings:
- Lines themselves use Windows line endings (\r\n)
- print_r() uses Unix line endings (\n)
So the log looks ugly in Notepad but looks normal in almost any other
editor. Your customer logger can take care of that. This works for me:
<?php
ini_set('log_errors', 1);
ini_set('error_log', 'error.log');
error_log(
strtr(
print_r(Array(1, 2, 3), 1),
array(
"\r\n" =PHP_EOL,
"\r" =PHP_EOL,
"\n" =PHP_EOL,
)
)
);
?>
--
--
http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
http://bits.demogracia.com
-- Mi web de humor al baño María:
http://www.demogracia.com
--