PHP_ Beautifier is very outdated! For a more modern approach try php-cs-fixer

Example command: php-cs-fixer fix --rules=@PSR2 path/to/php/src

A second alternative is PHP_CodeSniffer

Example command: phpcbf --standard=PSR2 path/to/php/src

Answer from Moak on Stack Overflow
๐ŸŒ
GitHub
github.com โ€บ lkrms โ€บ pretty-php
GitHub - lkrms/pretty-php: The opinionated PHP code formatter
Formats code written for PHP 8.4 and below (when running on a compatible version of PHP), including property hooks introduced in PHP 8.4 ยท Code is formatted for readability, consistency, and small diffs
Starred by 146 users
Forked by 3 users
Languages ย  PHP 98.3% | Shell 1.5% | Latte 0.2% | PHP 98.3% | Shell 1.5% | Latte 0.2%
๐ŸŒ
GitHub
github.com โ€บ mmoreram โ€บ php-formatter
GitHub - mmoreram/php-formatter: PHP Formatter is a PHP developer friendly set of tools
You can place a file named .formatter.yml in the root of your project. In every command execution, this will be the priority of the definitions. If an option is set in the command, this will be used. Otherwise, if is defined in a found config file, this will be used. Otherwise, default value will be used. ... use-sort: group: - _main - Mmoreram group-type: each sort-type: alph sort-direction: asc strict: ~ header: | /* * This file is part of the php-formatter package * * Copyright (c) 2014 Marc Morera * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code.
Starred by 169 users
Forked by 17 users
Languages ย  PHP 100.0% | PHP 100.0%
๐ŸŒ
Phpqa
phpqa.io โ€บ projects โ€บ php-formatter.html
PHP Formatter | PHP Quality Assurance
Download it: wget -O php-formatter.phar https://github.com/mmoreram/php-formatter/blob/master/build/php-formatter.phar?raw=true or curl -sSL https://github.com/mmoreram/php-formatter/blob/master/build/php-formatter.phar?raw=true -o php-formatter.phar Install it as an executable: chmod a+x php-formatter.phar sudo mv php-formatter.phar /usr/local/bin/php-formatter Use it: php-formatter
๐ŸŒ
JetBrains
jetbrains.com โ€บ help โ€บ phpstorm โ€บ command-line-formatter.html
Format files from the command line | PhpStorm Documentation
The command-line formatter launches an instance of PhpStorm in the background and applies the formatting. It will not work if another instance of PhpStorm is already running. In this case, you can perform code style formatting from the running ...
๐ŸŒ
GitHub
github.com โ€บ cmrcx โ€บ phptidy
GitHub - cmrcx/phptidy: This is a little tool for formatting PHP code.
This is a little tool for formatting PHP code. Contribute to cmrcx/phptidy development by creating an account on GitHub.
Starred by 45 users
Forked by 14 users
Languages ย  PHP 99.5% | PHP 99.5%
๐ŸŒ
Package Control
packagecontrol.io โ€บ packages โ€บ PhpBeautifier
PhpBeautifier - Packages - Package Control
You can define some options in the script php_beautifier.py. Default options are : PHP_OPTIONS = "-s4 -l 'ArrayNested()' " (indent with 4 spaces and nested arrays).
๐ŸŒ
Reddit
reddit.com โ€บ r/phphelp โ€บ what is the most common php code formatter?
r/PHPhelp on Reddit: What is the most common PHP code formatter?
August 1, 2024 -

I found three code formatters for PHP.

  • Prettier (With PHP Plugin)

  • PrettyPHP (https://github.com/lkrms/vscode-pretty-php)

  • phpfmt (https://github.com/kokororin/vscode-phpfmt)

I was able to setup Prettier with the PHP plugin but the setup is not ideal since I have to install prettier and the prettier PHP plugin from NPM into the project every single time which is not the case when using Prettier VSCode extension with HTML, JS and CSS. I do like how Prettier has its own configuration .prettierrc files and it allows you to set a standard format for a project you are collaborating with others, however I believe formatting should be done in the IDE such as using a VSCode extension and this is the case with the Prettier extension for HTML, JS and CSS but not for PHP since it requires NPM packages.

The other two do not look popular. Am I missing something? I would like to have a standard format or be able to have an opinionated format setup like Prettier for JS but for PHP.

Find elsewhere
๐ŸŒ
Packagist
packagist.org โ€บ packages โ€บ gossi โ€บ php-code-formatter
gossi/php-code-formatter - Packagist.org
composer require gossi/php-code-formatter ยท This simple code snippet is all you need: use gossi\formatter\Formatter; $formatter = new Formatter(); $beautifulCode = $formatter->format($uglyCode); A bare cli version is available: vendor/bin/phormat path/to/file.php ยท
๐ŸŒ
Laravel News
laravel-news.com โ€บ home โ€บ prettyphp is an opinionated code formatter for php
PrettyPHP is an opinionated code formatter for PHP - Laravel News
September 18, 2025 - PrettyPHP is an opinionated code formatter that is a fast, deterministic code formatter for PHP, written in PHP. It has sensible defaults and runs without configuration. ... This CLI also has a VS Code extension to format your files on save.
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
PHP Formatter PHP-CS-Fixer - Visual Studio Marketplace
Extension for Visual Studio Code - Format PHP files with PHP-CS-Fixer. Lightweight, zero dependencies, auto-discovers config and executable.
๐ŸŒ
Auraphp
auraphp.com โ€บ packages โ€บ 2.x โ€บ Cli
Aura for PHP : Aura.Cli
You can use special formatting markup in the output and error strings to set text color, text weight, background color, and other display characteristics. See the formatter cheat sheet below. <?php // print to stdout $stdio->outln('This is normal text.'); // print to stderr $stdio->errln('<<red>>This is an error in red.'); $stdio->errln('Output will stay red until a formatting change.<<reset>>'); ?>
๐ŸŒ
Shopware
developer.shopware.com โ€บ docs โ€บ products โ€บ cli โ€บ formatter.html
Formatter | Shopware Documentation
Shopware CLI includes a built-in code formatter for PHP, JavaScript, CSS, SCSS, and Admin Twig files. Use it to apply the Shopware Coding Standard automatically and keep your project consistent.
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
PHP Formatter - pretty-php - Visual Studio Marketplace
Visual Studio Code>Formatters>PHP Formatter - pretty-phpNew to Visual Studio Code?
๐ŸŒ
Encode64
encode64.com โ€บ home โ€บ formatters โ€บ php formatter
Free Online PHP Beautifier โ€“ Clean & Format PHP Code Instantly | Encode64
Got messy PHP code from legacy projects, quick hacks or copy-pasted snippets? This online PHP formatter runs your code through Prettier with the official PHP plugin, giving you PSR-12โ€“style output with consistent indentation, spacing and arrays in seconds. Perfect for Laravel, Symfony, WordPress, APIs and CLIs.
๐ŸŒ
Jdorn
jdorn.github.io โ€บ sql-formatter
SqlFormatter
<?php $sql = "-- This is a comment SELECT /* This is another comment On more than one line */ Id #This is one final comment as temp, DateCreated as Created FROM MyTable;"; echo SqlFormatter::compress($sql); SELECT Id as temp, DateCreated as Created FROM MyTable; The removeComments method removes all comments, but otherwise preserves the original formatting.
๐ŸŒ
Freek.dev
freek.dev โ€บ 1252-tools-to-automatically-format-php-javascript-and-css-files
Tools to automatically format PHP, JavaScript and CSS files - Freek Van der Herten's blog on Laravel, PHP and AI
January 18, 2022 - I've started using prettier (and the php parser/plugin) to format PHP code; because it's just so consistent. I used php-cs-fixer, for ages, but changed because there are loads of things it doesn't reformat.โ€” assertchris (@assertchris) January 21, 2019 ยท Happy formatting!
๐ŸŒ
GitHub
github.com โ€บ phpowermove โ€บ php-code-formatter
GitHub - phpowermove/php-code-formatter: A code formatting library for php
composer require gossi/php-cod... $beautifulCode = $formatter->format($uglyCode); A bare cli version is available: vendor/bin/phormat path/to/file.php ยท...
Starred by 31 users
Forked by 11 users
Languages ย  PHP 100.0% | PHP 100.0%