PHP Format in Visual Studio Code

1

Currently I have several php files that are messy, I mean it's something like this:

<thead>
            <tr style="background:#339999;color:white;">
              <th>ID</th>
                <th>APELLIDO PATERNO</th>
              <th>APELLIDO MATERNO</th>
                <th>NOMBRES</th>
            <th>DNI</th>
            <th>CARGO</th>     
            <th>RAZON SOCIAL</th>
                <th></th>
          </tr>
         </thead> 

and I would like to correct it as follows:

         <thead>
          <tr style="background:#339999;color:white;">
            <th>ID</th>
              <th>APELLIDO PATERNO</th>
              <th>APELLIDO MATERNO</th>
              <th>NOMBRES</th>
              <th>DNI</th>
              <th>CARGO</th>     
              <th>RAZON SOCIAL</th>
            <th></th>
          </tr>
        </thead>  

I could share some plugin or tool to order my code.

    
asked by Luis Vega 09.05.2018 в 19:09
source

4 answers

1

You must install the Prettier - Code formatter plugin for html css javascript however it does not support PHP, but in the html code works perfectly.

There is an extension of name PHP Formatter but I could not put it to run correctly on my VSCode.

Greetings ...

    
answered by 24.07.2018 в 08:16
0

You can sort them manually with Ctrl + alt and selecting each one this makes you have multi cursors, then you give the TAB key as many times as you want. This if you want to order it manually! Good luck!

    
answered by 30.08.2018 в 17:22
-2

Code formatting is available in VS Code through these keyboard shortcuts:

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • In Ubuntu Ctrl + Shift + I

Alternatively, you can find the shortcut, as well as others, through the editor search functionality, which opens with Ctrl + Shift + P (or Command + Shift + P on Mac), and then looking for format document .

Translated from the answer in Stack Overflow How do you format code in Visual Studio Code (VSCode)

    
answered by 09.05.2018 в 19:23
-2

I'm doing very well with this configuration:

{
  "php.validate.executablePath": "/usr/bin/php",
  "phpformatter.composer": true,
  "php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar",
  "php-cs-fixer.lastDownload": 1535374941673,
  "editor.fontFamily": "SFMono-Regular, Menlo, Monaco, 'Courier New', monospace",
  "editor.formatOnPaste": true,
  "editor.formatOnSave": true,
  "editor.formatOnType": true,
  "php-cs-fixer.formatHtml": true
}
    
answered by 30.08.2018 в 16:39