1

How should one format returned errors or console messages in a question on Stack Overflow?

Recently I ran into a PHP question that had an error as a code block:

PHP Warning:  file_get_contents(http://www.google.com/): failed to open stream: 
Network is unreachable in /var/www/api/get_contents.php on line 2

Whatever, I guess it looks fine, but the automatic syntax highlighting kind of makes it a little bit difficult to read.

1 Answer 1

2

Formatting these "output" messages as code blocks is just fine. If the automatic syntax highlighting proves bothersome, you can add an explicit syntax hint to disable it:

I get the following warning:

<!-- language: lang-none -->

    PHP Warning:  file_get_contents(http://www.google.com/): failed to open stream: 
    Network is unreachable in /var/www/api/get_contents.php on line 2

Alternatively, you can abuse inline code formatting (using backticks), to which syntax highlighting is never applied. That would look like this:

`PHP Warning:  file_get_contents(http://www.google.com/): failed to open stream: 
Network is unreachable in /var/www/api/get_contents.php on line 2`

and render like this:

PHP Warning: file_get_contents(http://www.google.com/): failed to open stream: Network is unreachable in /var/www/api/get_contents.php on line 2

1
  • Good tip on the explicit language declare. Thank you. Mar 29, 2013 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .