Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 8th, 2008, 11:35 PM
August Karlstrom
Guest
 
Posts: n/a
Default Human readable error_log

Hi,

I'm looking for a function that *returns* a human readable string
representation of an array rather than prints it so I can use it with
the error_log procedure. Any clues?


August
  #2  
Old October 9th, 2008, 02:15 AM
Curtis
Guest
 
Posts: n/a
Default Re: Human readable error_log

August Karlstrom wrote:
Quote:
Hi,
>
I'm looking for a function that *returns* a human readable string
representation of an array rather than prints it so I can use it with
the error_log procedure. Any clues?
>
>
August
You can use output buffering, or write a function that suits your own
needs.

<URL:http://php.net/manual/en/ref.outcontrol.php>

--
Curtis
  #3  
Old October 9th, 2008, 03:15 AM
macca
Guest
 
Posts: n/a
Default Re: Human readable error_log

On Oct 8, 11:27*pm, August Karlstrom <fusionf...@gmail.comwrote:
Quote:
Hi,
>
I'm looking for a function that *returns* a human readable string
representation of an array rather than prints it so I can use it with
the error_log procedure. Any clues?
>
August
$string = print_r($array,1);

The second param of print_r() is a bool for return value. If true,
print_r() returns the string to your variable instead of printing to
the screen.

RTM here:

http://uk.php.net/manual/en/function.print-r.php
  #4  
Old October 9th, 2008, 09:15 AM
August Karlstrom
Guest
 
Posts: n/a
Default Re: Human readable error_log

macca wrote:
Quote:
On Oct 8, 11:27 pm, August Karlstrom <fusionf...@gmail.comwrote:
Quote:
>Hi,
>>
>I'm looking for a function that *returns* a human readable string
>representation of an array rather than prints it so I can use it with
>the error_log procedure. Any clues?
>>
>August
>
$string = print_r($array,1);
>
The second param of print_r() is a bool for return value. If true,
print_r() returns the string to your variable instead of printing to
the screen.
>
RTM here:
>
http://uk.php.net/manual/en/function.print-r.php
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: ...


August
  #5  
Old October 9th, 2008, 09:45 AM
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=
Guest
 
Posts: n/a
Default Re: Human readable error_log

August Karlstrom escribió:
Quote:
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
--
  #6  
Old October 10th, 2008, 11:55 AM
August Karlstrom
Guest
 
Posts: n/a
Default Re: Human readable error_log

Álvaro G. Vicario wrote:
Quote:
August Karlstrom escribió:
Quote:
>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.
[...]

OK, thanks for the information Álvaro.


August
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles