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
🌐
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.

🌐
W3Docs
w3docs.com › php
Format code command for PHP/HTML in Visual Studio Code
Click the "Format" button to apply the formatting to the selected text. Alternatively, you can also use the keyboard shortcut Ctrl+Shift+I to automatically format the code in the current document.
🌐
Aslam Doctor
aslamdoctor.com › home › articles › php code sniffing & formatting in vscode
PHP Code Sniffing & Formatting in VSCode - Aslam Doctor
June 16, 2025 - PHP_CodeSniffer is a set of tools that allows linting and formatting of code in one package and it’s an independent tool. You can simply use it as a set of simple commands on the terminal.
🌐
Devsense
docs.devsense.com › vscode › formatting
Code Formatting - PHP Tools for Visual Studio - Documentation
This style focuses on leaving the code visual structure as untouched as possible while normalizing the whitespaces where possible. ... To turn off the formatting select the setting Off. Remaining features like PHPDoc auto-generation will work but Document Format, Selection Format, Format On Paste and Format On Type will do nothing. Use php.format.rules.* settings to configure the formatter to behave as you wish. For a detailed list of formatting options, either open the Settings Editor (Ctrl+,) and type php format in the Search bar or see our documentation page HERE.
🌐
YouTube
youtube.com › watch
Visual Studio Code Extension PHP Formatter - YouTube
Di video singkat ini, kita akan mencoba extension dari vscode yaitu php formatter, dengan extension ini, kita bisa dengan mudah merapikan kode kita secara ot...
Published   October 4, 2021
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.

🌐
Devsense
community.devsense.com › d › 145-formatting-issues-in-vs-code
Formatting issues in VS code - PHP Tools Community Forum | DEVSENSE
November 13, 2019 - 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!
Find elsewhere
🌐
GitHub
github.com › junstyle › vscode-php-cs-fixer › blob › master › README.md
vscode-php-cs-fixer/README.md at master · junstyle/vscode-php-cs-fixer
// Set PHP CS Fixer as the default formatter for PHP files // It will avoid conflict with other formatters like prettier etc.
Author   junstyle
🌐
Codethepixel
codethepixel.com › articles › Formatting-PHP-in-VSCode-Using-Prettier-and-PHP-Intelephense
CTP: Formatting PHP in VSCode Using Prettier and PHP Intelephense
June 15, 2025 - Learn how to set up Visual Studio Code (VSCode) for automatic PHP file formatting using the Prettier and PHP Intelephense extensions. This step-by-step tutorial will help you maintain a clean and organised codebase, enhancing your PHP development experience.
🌐
Lightning Job Search
lightningjobsearch.com › blogs › the-programmer-blog › how-do-you-format-code-in-visual-studio-code-vscode
How do you format code in Visual Studio Code (VSCode)?
The shortcut is usually Shift + Alt + F on Windows and Shift + Option + F on Mac. Alternatively, you can right-click in the code editor and select "Format Document" or "Format Selection" from the context menu.
🌐
Ask Ubuntu
askubuntu.com › questions › 1399008 › how-to-specified-pharpath-on-vscode-settings-json-file-in-ubuntu-20-04-for-usin
visual studio code - How to specified pharPath on VSCode settings.json file in Ubuntu 20.04, for using PHP Formatter extension? - Ask Ubuntu
March 24, 2022 - I have installed PHP Formatter extension on VSCode. I' trying to Format Document but I have this log: Neither a pharPath or use of Composer was specified. Aborting... I installed php based on Ondr...
🌐
YouTube
youtube.com › watch
Installing and setting up PHP code formatter extension or php cs fixer on Visual Studio Code - YouTube
Installing and setting up PHP code formatter extension or php cs fixer on Visual Studio Code:Follow this article:https://medium.com/@armorasha/php-cs-fixer-h...
Published   September 15, 2021
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › php
PHP in Visual Studio Code
November 3, 2021 - Learn about Visual Studio Code editor features (syntax highlighting, snippets, linting) and extensions for PHP.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Instead of manually enforcing style rules or debating formatting choices in code reviews, you can automate the process using a tool like Prettier - a popular, opinionated code formatter. In this article, you’ll learn how to set up and use Prettier in Visual Studio Code (VS Code) to automatically format your code.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier - Code formatter - Visual Studio Marketplace
January 21, 2026 - Extension for Visual Studio Code - Code formatter using prettier
🌐
Sentry
sentry.io › sentry answers › vs code › format code in visual studio code
Format code in Visual Studio Code | Sentry
To format the contents of the current file, we can either use the shortcut Ctrl+Shift+I (Command+Shift+I on macOS) or bring up the command palette with Ctrl+Shift+P (Command+Shift+P on macOS) and then search for and execute “Format Document”. ...
🌐
Visual Studio Code
code.visualstudio.com › docs › configure › keybindings
Keyboard shortcuts for Visual Studio Code
November 3, 2021 - Visual Studio Code lets you perform most tasks directly from the keyboard. This article explains how you can modify the default keyboard shortcuts that come with VS Code.
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › codebasics
Basic editing
November 3, 2021 - Visual Studio Code is an editor first and foremost, and includes the features you need for highly productive source code editing. This topic takes you through the basics of the editor and helps you get moving with your code. Being able to keep your hands on the keyboard when writing code is crucial for high productivity. VS Code has a rich set of default keyboard shortcuts as well as allowing you to customize them.