PHP Code Formatter
Format and beautify PHP code with consistent indentation. Free online PHP beautifier.
About This Tool
The PHP Code Formatter beautifies PHP source code by applying consistent indentation and normalizing spacing. Paste minified, compressed, or poorly indented PHP and get clean, readable output in seconds. Whether you received obfuscated code, copied a snippet from a legacy project, or just want to quickly standardize formatting, this tool handles it without any setup.
All formatting runs entirely in your browser β no PHP code is sent to any server. Your source code stays private. This tool uses an indentation-based reflow algorithm that tracks brace depth. For full PSR-12 compliance, use PHP-CS-Fixer in your IDE; this tool is best for quick, on-the-go reformatting.
How to Use
- Paste your PHP code into the Input PHP area, or click Sample to load an example.
- Choose your preferred indent size: 2 spaces or 4 spaces (PSR-12 standard is 4).
- Click Format to apply indentation.
- Review the formatted output, then click Copy to copy it to your clipboard.
Use Cases
Backend developers paste minified PHP from deployment bundles or legacy codebases and need to read it quickly. Security researchers deobfuscate PHP scripts to inspect their behavior. Freelancers receiving poorly formatted client code reformat it before making edits. Students learning PHP format textbook examples to understand control flow. Developers working on mobile devices or Chromebooks use this tool when their IDE is unavailable.
FAQ
- Does this follow PSR-12 standards? β This tool applies consistent brace-based indentation, which aligns with PSR-12 structure. For full PSR-12 compliance including line length limits and operator spacing, use PHP-CS-Fixer.
- Can it handle PHP mixed with HTML? β Yes, the formatter will preserve HTML sections and only reindent lines within PHP blocks.
- Why is my heredoc not formatted correctly? β Heredoc strings (nowdoc/heredoc syntax) contain significant whitespace. The formatter preserves their content to avoid breaking string values.
- Is my code sent to a server? β No. All processing happens in your browser using JavaScript. Your PHP code never leaves your device.