How to display php errors in a more readable format

In php.ini there are several settings that can be adjusted to create a readable result.

  1. display_errors = On - this one is not directly related to the question, but for obvious reasons I thought it should be included;
  2. html_errors = On - php engine will render the errors as a HTML page, not just plain text;
  3. error_prepend_string = "<pre>" (really important in some cases);
  4. error_append_string = "</pre>" (really important in some cases).

3 and 4 are needed for when PHP inserts the error in a HTML page with just new line characters and no <br> tags. Those settings will encapsulate the error inside a <pre> tag, so new line characters will be preserved.

Of course, you can add styles inside the <pre> tag. For example, I use

"<pre style='white-space: pre-line'>"

to allow line breaks on really long lines.


It's a PHP setting, not specific to any *AMP platform, set in php.ini:

html_errors = 1

relevant docs: http://www.php.net/manual/en/errorfunc.configuration.php#ini.html-errors