473,553 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13534
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...@gma il.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...@gma il.comwrote:
>Hi,

I'm looking for a function that *returns* a human readable string
representati on 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_er rors', 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_er rors', 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(prin t_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
2993
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 intuitive to read and edit 3) easyly readable into a python datastructure (a dictionary?) 4) not requiring any heavy libraries needed (I am distributing my proggie as a py2exe executable and do not want...
1
7539
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 to import it into a SQL Server database in an automated fashion. I am not really concerned about how many tables it requires or what the schema looks like as long as the data remains related and...
9
5960
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' implements. There's no python function that I could find to perform this formatting , so I've taken a stab at it: import math def human_readable(n, suffix='B', places=2): '''Return a human friendly...
4
2161
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 error meesages to the end user when/if a database exception occurs. I am using the type 4 Universal JDBC driver. If I have an SQLCODE & SQLSTATE, where do I look to get a human...
4
2952
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
2776
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 representing the date to a human readable format. Thanks for your help,
5
1725
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 data that the user enters through a webform. The form is an operations schedule for a piece of equipment. Basically, the schedule consists of repeated actions by the machine, and it is very...
3
3589
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 that i can read the information contained in this file. Is it possible to develope a program in JAVa for this purpose???? if yes then please give me some clue for this......
0
1473
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 table to something like:: _abbrevs = (and add a 'B'). --
0
7568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7772
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5133
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3537
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3525
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1990
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1106
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.