- PHP Formatter
- Why use Online PHP Beautifier?
- Как форматировать php код
- Triggering format
- Configuration
- Code Styles
- Code Style: PSR-12
- Code Style: PSR-2
- Code Style: Allman
- Code Style: K&R
- Code Style: Laravel
- Code Style: WordPress
- Code Style: Drupal
- Code Style: PHP Tools
- Code Style: Off
- Custom Code Style
- HTML, JS and CSS Formatting
- PHP Beautifier
- What can you do with PHP Formatter?
- What is PHP?
- Example of PHP
PHP Formatter
Using PHP Formatter is a helpful and straightforward way to format PHP data and share it with others. PHP code alignment and indentation are made easier with it. Use our online PHP formatter to make your PHP code neat and clear without having to go through any obstacles.
Every user around the world can format PHP files with our tool with just one click. The online PHP formatting service does not require users to register on our website. The tool is of premium quality, but there is no need to pay for a premium version to use it. Our PHP file formatter allows you to fully format any uploaded files, no matter how long they are.
Why use Online PHP Beautifier?
This program reformat and beautify PHP source code files automatically. There is nothing ordinary about the PHP code formatter we offer. Using this tool, users can easily format PHP and enjoy top-notch features. With this tool, you can take advantage of the following features.
Cost-free
You can format as many files as you want and use the PHP code beautifier for free. In the future, this tool will not become a premium one. Users are not charged for its use.
Compatibility
All devices, including Macs, desktops, laptops, and smartphones, can access this website. This tool can be used with any operating system, including Windows, Macintosh, iOS, and Android.
Get quick results
With only a few seconds, you can have your PHP code beautified. The process of creating a PHP file is no longer labor-intensive, as you can access a formatted PHP file immediately.
Programming can be fun, so can cryptography; however they should not be combined.
Kreitzberg and Shneiderman
Как форматировать php код
The integrated formatter helps you keep the code looking clean and maintain the selected code style (e.g. «PSR-12» ).
Note: In order to format the document, it must be syntax-error free.
The code formatting normalizes whitespaces, line endings, opening and closing braces, indentation, adds or removes new lines when necessary and pretty print spaces. It can also be highly customized.
Triggering format
The formatting can be triggered explicitly by two actions:
- Format Document ( Shift+Alt+F ) — Format the entire active file.
- Format Selection ( Ctrl+K Ctrl+F ) — Format the selected text.
Or it can be triggered based on specific user actions, such as typing, saving or pasting. You can alter this behavior by setting:
- editor.formatOnType to true which enables the editor to format code blocks and statements upon typing ; and > .
- editor.formatOnSave to true instructs the formatter to run when saving the document.
- editor.formatOnPaste to true triggers format when pasting.
Configuration
The formatting behavior is set in settings.json . All the relevant settings and their effects are summed up in the following table.
Setting | Effect |
---|---|
editor.insertSpaces | Spaces are used to indent code if true , tabs are used otherwise. |
editor.tabSize | Number of spaces that represent a single tab, this value is used only when editor.insertSpaces is true |
editor.formatOnType | Enables or disables automatic formatting of code block upon typing ; or > . |
php.format.codeStyle | The code style that formatter is going to follow. |
php.format.rules.* | The formatting rules which override the selected code style |
Code Styles
There are various code styles available:
Code Style: PSR-12
This formatting style is compliant with PSR-12 which expands and replaces PSR-2, and requires adherence to PSR-1.
Code Style: PSR-2
This formatting style is compliant with PSR-1 and PSR-2 standards.
Feature | Behavior |
---|---|
Multi-line expressions | Subsequent lines are indented one level deeper than the initial line |
Code blocks | Body of a declarations starts on a new line, while control flow block starts on the same line as the construct |
// Multi-line expressions $x = $a + $b + $c;
Code Style: Allman
The Allman style is named after Eric Allman. This style puts the braces on the next line. This applies to all control statements and declarations.
Code Style: K&R
The K&R style (Kernighan & Ritchie Style) keeps open braces on the same line for control structures, types, functions and methods.
Code Style: Laravel
Laravel follows the PSR-2 coding standard with few formatting specifics we’ve added to this code style.
Code Style: WordPress
This formatting style is compliant with WordPress PHP Coding Standards.
Code Style: Drupal
This formatting style is compliant with Drupal PHP Coding Standards.
Code Style: PHP Tools
The default code style is compliant with the formatting in PHP Tools for Visual Studio. This style focuses on leaving the code visual structure as untouched as possible while normalizing the whitespaces where possible.
Feature | Behavior |
---|---|
Multi-line expressions | Subsequent lines maintain their indentation from the first line. |
Code blocks | Code blocks always start on a new line for both declarations and code. |
// Multi-line expressions $x = $a + $b + $c;
Code Style: Off
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.
Custom Code Style
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.
HTML, JS and CSS Formatting
PHP Tools support HTML, JavaScript and CSS formatting in PHP files. The formatting of these different language sections is performed according to VS Code settings. To customize it, please consult the official VS code documentation for:
PHP Beautifier
PHP Formatter helps to format unformatted or ugly PHP data and helps to save and share PHP. It helps to indent and do the php code alignment.
What can you do with PHP Formatter?
- It helps to beautify your PHP. It will generate Clean up PHP code.
- This tool allows loading the PHP URL to beautify. Click on the URL button, Enter URL and Submit.
- This tool supports loading the PHP File to beautify. Click on the Upload button and select File.
- It beautify pure PHP framework file such as Laravel, CodeIgniter, YII, CakePHP, Symfony and many more one file at a time.
- PHP Source Code Beautifier Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.
What is PHP?
PHP is a popular language of programming for web development. It is executed on the server because it’s server side executing language and the resulting HTML is sent to the client’s web browser. PHP is often used to create dynamic web pages that interact with databases.
It is widely used to develop content management systems, forums, and other applications requiring user input or data storage. PHP is known for being easy to learn and use, and a large and active community of developers supports it.
Example of PHP
id = $id; $this->name = $name; > public function message() < return "My Car Insurance's ID is " . $this->id ." and Name is " . $this->name . "!"; > > $myCarInsurance = new CarInsurance("1", "State Farm"); echo $myCarInsurance->message(); echo "
"; $myCarInsurance = new CarInsurance("2", "Geico"); echo $myCarInsurance->message(); ?>