Skip to content
CODE FORMATTING & MINIFICATION

PHP Code Formatter Online

Indent PHP code and put each statement on its own line.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

PHP Code Formatter

About PHP Code Formatter

The PHP Code Formatter indents blocks and puts each statement on its own line, using the same brace and semicolon logic as the JavaScript formatter. Strings in single or double quotes, and both // and /* */ comments, are left exactly as typed.

It is meant for quick clean-ups of snippets, WordPress functions and code copied from forums. It does not apply the PSR-12 standard or reorder anything, so run PHP_CodeSniffer or PHP-CS-Fixer in your project when you need strict style enforcement.

How to use PHP Code Formatter

  1. Paste your PHP code into the input box. You can include the opening <?php tag.
  2. Click Run Tool to format it.
  3. Copy the formatted code back into your file.

Example

Input

<?php function nhp_greet($name){ if(empty($name)){ return "Hello, guest"; } else { return "Hello, ".esc_html($name); } }

Output

<?php function nhp_greet($name) {
  if(empty($name)) {
    return "Hello, guest";
  } else {
    return "Hello, ".esc_html($name);
  }
}

Common uses

  • Making a one-line plugin or theme snippet readable.
  • Cleaning up code copied from a tutorial before adapting it.
  • Checking brace nesting in a long function.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Does it check PHP syntax?

No. It formats text. To check for balanced brackets and quotes, use the PHP Syntax Checker on this site.

Does it handle HTML mixed with PHP?

Basic mixing works, but the formatter treats the whole input as code. Format templates with large HTML sections in your editor instead.

Does it change my variable names or quotes?

No. Only whitespace and line breaks are adjusted.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.