Code The Pixel

Formatting PHP in VSCode Using Prettier and PHP Intelephense

Asyraf Wahi Anuar - June 15, 2025
Published in Tools & Software 5785 Views Email This Article
Estimated reading time: 1 minute, 16 seconds
Visual Studio Code (VSCode) is a popular code editor renowned for its versatility and numerous extensions that enhance the coding experience. Among these, the Prettier extension stands out for its ability to format code consistently across various languages, making it a favourite among developers. However, when it comes to formatting PHP files, many users encounter challenges, as Prettier does not natively support PHP formatting. This limitation can be frustrating, especially for those looking to maintain a clean and organised codebase in PHP.
 
In this tutorial, I will guide you through the steps to effectively set up your VS Code environment to automatically format PHP files using Prettier in conjunction with the PHP Intelephense extension. By following this guide, you'll be able to streamline your PHP development process and ensure your code looks sharp and professional. Let’s dive in and unlock the full potential of code formatting in VSCode!
 
1. Install and enable the Prettier Extension in VS Code
2. Set as default formatter in VS Code settings:
a) File - Preferences - Settings / Shortcut: CTRL + ,
b) Search: Formatter
c) Editor: Default Formatter select: Prettier - Code Formatter
 
3. Install and enable the PHP Intelephense
4. CTRL + Shift + P then search for "open user settings (JSON)" and insert the following parameter:
{
... //other config
  "[php]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
  },
  "editor.linkedEditing": true
...
}
 
All files ending with the .php extension will be formatted using the PHP Intelephense extension. Make sure to securely save the settings.json file to preserve these configurations for future use.

Cite this article (APA 6th Edition)