PHP Formatter

Beautify messy PHP code with consistent indentation, spacing and brace style.

Website Management Tools

About the PHP Formatter

The PHP Formatter takes messy or squashed PHP code and lays it out with consistent indentation and spacing. You can pick your indent size, including the 4 spaces used by the PSR-12 style, and it reports the number of lines, functions and classes in your code.

Consistent formatting makes code far easier to read and review. It is especially helpful with old scripts, code copied from a forum, or a file that has been edited by several people with different habits.

The formatter only changes layout. It does not run your code, check that it works or find errors. Your code stays in your browser. For big projects, developers often use a dedicated tool in their editor, so that formatting happens automatically.

How to use this tool

  1. 1Paste your PHP code, or load the sample.
  2. 2Choose the indent size.
  3. 3Review the formatted result.
  4. 4Copy it back into your file and test it.

Best-practice tips

  • Keep a backup of the original before replacing a working file.
  • Use 4 spaces if you want to follow the PSR-12 standard.
  • Format one file at a time, so that changes are easy to review.

Answers

PHP Formatter FAQs

No. It only changes the layout. Errors will appear when the code runs.

Related tools

Continue with these related website management tools.