Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

How can I get new lines in php error reporting messages?

Simple question, but can't find the answer.

When my PHP script generates multiple errors or warnings, etc. they all appear without any line breaks.  I have to figure out where each error message starts and stops.  How can I configure my php setup so that it places new line breaks after each error message so it is easier to decipher when it displays in my browser.

ALSO, I want to do this globally to the server, not just a particular script.

Thanks!
0
ariestav
Asked:
ariestav
  • 4
  • 2
  • 2
  • +1
1 Solution
 
Cornelia YoderArtistCommented:
What kind of errors or warnings are you getting?  Syntax errors usually die after the first one.  
0
 
ariestavAuthor Commented:
my error reporting is set to E_ALL.  So the warnings are annoyingly difficult to decipher.  
0
 
Ray PaseurCommented:
Please post a link to a web page that generates the kind of messages you describe, thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Hugh McCurdyCommented:
Since you are interested in an answer for the server, I'm going to assume you control the server.  (Have admin access.)

The errors might be easier to read in the error_log file.  On my development computer, the file is in the folder /var/log/httpd
Look at the end of that file.  In Linux, I use the tail command to look at the last few lines.  My log file gives me the line # where the error occurred.  

On my system, the location of the error_log file is defined in /etc/httpd/httpd.conf


There are controls for how php behaves in the php.ini file.  On my development computer, php.ini is in a folder called /etc/httpd

In the meantime, I'm with Ray on this one.  It would really help to see the errors.
0
 
ariestavAuthor Commented:
The errors are "Notices" and "Warnings", they are not syntactical.  These errors output to the webpage for which the scripts builds after the request is done.  I don't want to look in an error_log file to find out what the error is--I already know what the error is.  I just want the format / display of the errors that appear in my output / echo's to be formatted better.

Thanks!
0
 
Hugh McCurdyCommented:
Would this work for you?

echo "Warning: phone number not specified<br />";
echo "Warning: zip code doesn't match state<br />";

Open in new window

0
 
ariestavAuthor Commented:
They would, but there is no way to add br's to errors output by the php parser.  I can't get ahold of the engine that outputs those.  If I could, I would manipulate each string that gets output from there.
0
 
Ray PaseurCommented:
Please see http://www.laprbass.com/RAY_temp_ariestav.php

This script will capture and change a Notice caused by the use of an undefined variable on line 8.  But even though this is technically possible, it seems like a better idea (to me, at least) to just fix the programming instead of trying to modify the error messages!
<?php // RAY_temp_ariestav.php
error_reporting(E_ALL);

// START THE OUTPUT BUFFER
ob_start();

// CAUSE A NOTICE
$x = $y;

// CAPTURE THE NOTICE
$notice = ob_get_clean();

// CHANGE THE CAPTURED NOTICE
$redact = str_replace(' in ', ' in <br/>', $notice);
$redact = str_replace(' on ', ' <br/>at ', $redact);

// SHOW THE WORK PRODUCT
echo "<br/>ORIGINAL NOTICE: <br/>$notice<br/>";
echo "<br/>REDACTED NOTICE: <br/>$redact<br/>";

Open in new window

0
 
ariestavAuthor Commented:
Thank you Ray.  This was good.  I hadn't thought of doing that.  I agree that fixing them is better.  But in some cases, I want to be able to decipher the messaging coming from PHP.  This will help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now