php-cs-fixer https://github.com/PHP-CS-Fixer/PHP-CS-Fixer I do disagree on code standards being enforced in the IDE. My view is they absolutely need to be enforced at the project level to ensure consistency of code standard throughout that project. The IDE should be capable of configuring itself based on project owned configurations (this is the case when using php-cs-fixer). Edit: To your point of having an opinionated standard set out of the box. PSR12 https://www.php-fig.org/psr/psr-12/ . A rulset for this standard already exists in php-cs-fixer. Edit 2: For absolute transparency, there is also another popular capable of doing everything I mentioned above - https://github.com/squizlabs/PHP_CodeSniffer Answer from JParkinson1991 on reddit.com
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ html-formatter.html
Free Online HTML Formatter - FreeFormatter.com
This free online HTML formatter and validator lets you chose your indentation level and also lets you export to file
๐ŸŒ
Code Beautify
codebeautify.org โ€บ php-beautifier
PHP Beautifier and PHP Formatter Online
PHP Beautifier online helps to format and indent the php source code and help to share with others.
Discussions

What is the most common PHP code formatter?
php-cs-fixer https://github.com/PHP-CS-Fixer/PHP-CS-Fixer I do disagree on code standards being enforced in the IDE. My view is they absolutely need to be enforced at the project level to ensure consistency of code standard throughout that project. The IDE should be capable of configuring itself based on project owned configurations (this is the case when using php-cs-fixer). Edit: To your point of having an opinionated standard set out of the box. PSR12 https://www.php-fig.org/psr/psr-12/ . A rulset for this standard already exists in php-cs-fixer. Edit 2: For absolute transparency, there is also another popular capable of doing everything I mentioned above - https://github.com/squizlabs/PHP_CodeSniffer More on reddit.com
๐ŸŒ r/PHPhelp
19
7
August 1, 2024
Formatting PHP code in vscode, using prettier, on save

No one should ever format on save, on projects where you work in a team, it will be an never ending whitespace war. And it will seriously pollute your VCS diff's with unrelated whitespace changes, and potentially create conflicts along the way. Please don't.

The only valid use case of reformatting on save is when it's a project requirement, everyone uses the same tooling, editor, and formatting rules. Under any other scenario, please don't.

More on reddit.com
๐ŸŒ r/PHP
27
24
October 15, 2017
People also ask

Is this online PHP formatter free?
Yes, this tool is completely free to use online without any usage restrictions or mandatory sign-up.
๐ŸŒ
codeshack.io
codeshack.io โ€บ home โ€บ tools โ€บ php formatter
PHP Formatter - Beautify and Format PHP Code Online
What does a PHP Formatter do?
A PHP Formatter analyzes your PHP script and automatically applies consistent formatting rules for indentation, spacing, line breaks, brace style, and more, based on standards like PSR-12 or Prettier's defaults. It makes messy or inconsistently styled code clean and readable without changing its logic.
๐ŸŒ
codeshack.io
codeshack.io โ€บ home โ€บ tools โ€บ php formatter
PHP Formatter - Beautify and Format PHP Code Online
Does this tool fix bugs or errors in my PHP code?
No. This is a code formatter, not a debugger or static analyzer (linter). It focuses on code style and structure. While it might fail on severe syntax errors, it won't find logical errors, security vulnerabilities, or runtime issues in your PHP script.
๐ŸŒ
codeshack.io
codeshack.io โ€บ home โ€บ tools โ€บ php formatter
PHP Formatter - Beautify and Format PHP Code Online
๐ŸŒ
Smallseotools
smallseotools.com โ€บ online-php-formatter
PHP Formatter - Beautify Your Unorganized PHP Code Online
PHP formatter helps you to beautify unorganized, minified, or ugly PHP file code. Clear your PHP code indentation level to make it easily readable.
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ php formatter
PHP Formatter - Beautify and Format PHP Code Online
Format and beautify your PHP code online according to PSR standards. Paste messy PHP or load a file, choose indentation and PHP version, and get clean code.
๐ŸŒ
Duplichecker.com
duplichecker.com โ€บ php-formatter
PHP Formatter - Beautify Your Messy PHP Code Online
PHP Formatter helps you to Beautify your ugly, minified PHP code to make it easily readable. Just upload/paste PHP Code and Get formatted PHP online.
๐ŸŒ
BeautifyTools
beautifytools.com โ€บ php-beautifier.php
Online PHP Beautifier - PHP Formatter - BeautifyTools.com
Online PHP Beautifier, PHP Formatter beautifies dirty, ugly or unreadable PHP code and give it proper indentation. It supports various indentation styles such as K&R style, Allman style, Whitesmiths style and GNU style.
Find elsewhere
๐ŸŒ
Eternitech
eternitech.com โ€บ online-tools โ€บ php-beautifier
PHP Beautifier | Free Online PHP Beautifier Tool
April 10, 2023 - Make your PHP Code more Beautiful & Professional with the help of the Free Online PHP Beautifier. Just need to copy, paste & format. You will get results in seconds
๐ŸŒ
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.

๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
Format HTML in PHP - Visual Studio Marketplace
Extension for Visual Studio Code - Provides formatting for the HTML code in PHP files using JSbeautify - Works well paired with a PHP formatting extension
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ tidy.examples.basic.php
PHP: Tidy example - Manual
<?php ob_start(); ?> <html>a html document</html> <?php $html = ob_get_clean(); // Specify configuration $config = array( 'indent' => true, 'output-xhtml' => true, 'wrap' => 200); // Tidy $tidy = new tidy; $tidy->parseString($html, $config, 'utf8'); $tidy->cleanRepair(); // Output echo $tidy; ?>
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ online_php_formatter.htm
Online PHP Formatter | Tutorialspoint
Online PHP Formatter and Beautifier - Try online PHP Code formatter and beautifier and Editor to beautify and format PHP code using jQuery Plug-in
Top answer
1 of 14
104

Update 2021-07-21

It's been more than half a decade since I first wrote this answer. The extensions to which I originally linked are abandoned, and Visual Studio Code's intrinsic PHP support hasn't improved, which is disappointing. The only decent extension still standing of which I'm aware is PHP Intelephense, which uses a freemium model: basic features are free, and a lifetime license is $12 USD as of writing.

The free version of Intelephense supports code formatting with the usual shortcuts (Alt + Shift + F on Windows and Linux, โŒฅโ‡งF on macOS). Visual Studio Code continues to lack built-in support for PHP code formatting and will direct you to the extension marketplace if you attempt to format PHP without an appropriate extension installed.

Original answer

Visual Studio Code has pretty awesome PHP support. What it lacks is covered by extensions. A quick search reveals at least three (1, 2, and 3) that claim to support PHP formatting.

They mostly seem to use the standard shortcut of Alt + Shift + F on Windows/Linux, with varying shortcuts on Mac. If you're on Mac, give โŒฅโ‡งF a try.

2 of 14
52

I installed

  • Prettier for HTML, CSS, and JavaScript files

  • PHP Intelephense for PHP files

I followed the instructions for each plugin but found I had to additionally edit settings.json manually in order to get them to work together.

"editor.defaultFormatter": "esbenp.prettier-vscode",
"[php]": {
  "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}

The settings use Intelephense as the formatter for PHP files and use Prettier as the formatter for all other files.

Now I use Shift + Alt + F to format the files like everybody else.

๐ŸŒ
GitHub
github.com โ€บ lcherone โ€บ php-format-html
GitHub - lcherone/php-format-html: A simple to use HTML prettifier/formatter class written in PHP.
<?php include_once('format.php'); $html = 'Unformatted HTML string'; // use spaces at 4 length echo Format::HTML($html); // use spaces at 2 length echo Format::HTML($html, true, 2); // use tabs echo Format::HTML($html, false);
Author ย  lcherone
๐ŸŒ
Text Cleaner
textcleaner.net โ€บ home โ€บ php formatter
PHP Formatter and Beautifier to format PHP online
July 23, 2023 - PHP Formatter: Online PHP formatter to beautify and format PHP code and file. Enter your minified PHP in the code editor, then click on the format button to make it pretty, clean, and readable. How to Use PHP Formatter Online Easy steps use PHP formatter online: Step 1: Paste your PHP code ...
๐ŸŒ
Devsense
community.devsense.com โ€บ d โ€บ 537-formatting-multiple-languages-php-javascript-html
Formatting Multiple Languages (PHP, Javascript, HTML) - PHP Tools Community Forum | DEVSENSE
March 3, 2022 - Welcome to our community forum. This is an open discussion forum where we try to help and guide you through using Devsense's PHP Tools software. We're here to help!
๐ŸŒ
Textmagic
freetools.textmagic.com โ€บ source-code-formatter
Source code formatter & beautifier - Textmagic
Use our free source code formatter to instantly transform, beautify, and format HTML, XML, CSS, JavaScript, PHP, or JSON code.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ utilities โ€บ php-formatter
Online PHP Formatter and PHP Beautifier (Free & Easy to Use) - GeeksforGeeks
February 2, 2026 - Click here to check out other formatters!!! The PHP Formatter is an indispensable tool that ensures readability and consistency in your PHP code.
๐ŸŒ
GitHub
github.com โ€บ mihaeu โ€บ html-formatter
GitHub - mihaeu/html-formatter: HTML Formatter is a PHP library which pretty prints HTML.
HTML Formatter is a PHP library which pretty prints HTML. - mihaeu/html-formatter
Starred by 17 users
Forked by 11 users
Languages ย  PHP 100.0% | PHP 100.0%