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
- Paste your PHP code into the input box. You can include the opening <?php tag.
- Click Run Tool to format it.
- 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.