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
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
For a PHP beautifier, you can also use this pear package PHP_Beautyfier, which can either be called from the command line or instantiated within your own PHP code. For the Javascript one instead, find an open discussion here
Videos
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.
I regularly use a tool called HTML Tidy to clean up dirty HTML. The Ubuntu package is simply called "tidy".
For PHP there seems to exist a tool called phptidy, but apart from testing if it works, I never used it.
If you have worked with Python before and the code is HTML or XML, then I would suggest using BeautifulSoup and automate the process for all files. In a Python console run this:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc)
print(soup.prettify())
Here html_doc is just the text of the file to be indented.
Or the non-geeky was is to use some IDE to get it done individually.