PHP Viewer

Paste PHP that arrived as one flat blob and read it with colours, indentation and line numbers.

PHP source
Highlighted PHP
Runs locally in your browser

About the PHP Viewer

Code pasted out of a log line, a database column or a chat message usually arrives without indentation and without colour, which makes even a short class hard to follow. This viewer re-indents the source first, then paints it: keywords in blue, strings in green, numbers in amber, comments in grey and every $variable in the site accent colour so the data flow stands out at a glance.

The highlighter is written for PHP specifically rather than borrowed from a generic C style lexer. It understands both comment styles plus the hash comment, single and double quoted strings with backslash escapes, backtick shell strings, heredoc and nowdoc blocks that run over many lines, namespace separators inside identifiers, and the <?php, <?= and ?> boundaries. Markup that sits outside those boundaries is shown in plain text, which makes an old template file with HTML wrapped around short PHP blocks readable rather than confusing.

Line numbers sit in a gutter that is skipped when you select text, so copying from the output gives you clean code with no numbers glued to the front. The Copy button always hands back the plain source, not the coloured markup. Re-indentation only moves whitespace between tokens, so strings, comments and heredoc bodies survive character for character. If you would rather download a rewritten file than read one, the PHP Beautifier does the same indentation pass and gives you text output.

How to use

  1. Paste PHP, or a whole template with HTML around it, into the left pane.
  2. Leave Re-indent first ticked when the source arrived on a single line.
  3. Turn off Line numbers if you want an unbroken block to screenshot.
  4. Use Copy to take the plain source away without any highlighting markup.

Common questions

Does the viewer run my PHP?
Never. There is no interpreter here at all. The text is tokenised and coloured, which is why it is safe to paste code you have not read yet.
Why is one of my strings coloured to the end of the file?
That happens when a quote is never closed. The unterminated string is the bug, and the colour run shows you exactly where it starts.
Are heredoc blocks handled?
Yes. Both heredoc and nowdoc are treated as one string token from the opening marker to the closing identifier, so braces inside them do not disturb the indentation.
Can I paste a Blade or Twig template?
You can, and the PHP parts will still be coloured, but the template directives are shown as plain text because they are not PHP syntax.