472,342 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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
Oct 8 '08 #1
5 13391
August Karlstrom wrote:
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
Oct 9 '08 #2
On Oct 8, 11:27*pm, August Karlstrom <fusionf...@gmail.comwrote:
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
Oct 9 '08 #3
macca wrote:
On Oct 8, 11:27 pm, August Karlstrom <fusionf...@gmail.comwrote:
>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
Oct 9 '08 #4
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
--
Oct 9 '08 #5
Álvaro G. Vicario wrote:
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.
[...]

OK, thanks for the information Álvaro.
August
Oct 10 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and...
1
by: Sven | last post by:
Hello, I am receiving a text file that is produced from a mainframe that is out of my control. I am attempting to find a (hopefully clean) way...
9
by: Alex Willmer | last post by:
When reporting file sizes to the user, it's nice to print '16.1 MB', rather than '16123270 B'. This is the behaviour the command 'df -h'...
4
by: aj | last post by:
DB2 WSE 8.1 FP5 Red Hat Linux AS 2.1 I am working on a Java-Swing based interface for a DB2 database, and want to display more human-readable...
4
by: John Baro | last post by:
I need to determine which fonts are human readable. Webdings, wingdings etc.. are not. Is there any easy way to accomplish this? Cheers JB
5
by: mphanke | last post by:
Hi, can somebody tell me how to convert the date from a Paradox .DB to human readable format? I need to write a tool to convert the 4 Bytes...
5
by: Captain Dondo | last post by:
I am working on an embedded platform. Disk storage is at a premium, so I am trying not to add any more stuff.... I am reading and writing some...
3
by: Sanyog Garg | last post by:
hi I want to open a binary file that contains information in Ulong, Int and char form. now i want to convert this file into human readable form so...
0
by: Rob Weir | last post by:
On 13 Aug 2008, rkmr wrote: http://mail.python.org/pipermail/python-list/1999-December/018519.html is a good start - just need to change the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.