PHP Formatter
Format PHP code with Prettier and the official PHP plugin, PSR-12 style, with a target PHP version setting.
Runs in your browserPHP → PHP
Loading tool…
Example
<?php
function add($a,$b){return $a+$b;}
echo add(1,2);<?php
function add($a, $b)
{
return $a + $b;
}
echo add(1, 2);How to use the PHP Formatter
- Include the opening <?php tag. Files that mix HTML and PHP are supported.
- Pick the oldest PHP version your code must run on; newer versions allow trailing commas in multi-line calls.
Privacy and limitations
- Your data is processed on your device and is not uploaded to any server.
- Code must parse as valid PHP for the selected version; syntax errors are reported with a line number.
- HTML outside <?php ?> blocks is kept as-is rather than reformatted.
Related converters
PHP Syntax HighlighterHighlight PHP code with variables, functions and strings coloured, exported as HTML.HTML BeautifierBeautify HTML with Prettier: consistent indentation plus formatting of embedded CSS and JavaScript.Java FormatterFormat Java source code with Prettier and prettier-plugin-java: classes, records, lambdas, generics and long call chains.GraphQL FormatterFormat GraphQL queries, mutations, fragments and schema definitions (SDL) with Prettier.Markdown FormatterNormalise Markdown with Prettier: consistent list markers, headings, emphasis and table alignment.Less FormatterFormat Less stylesheets with Prettier, keeping variables, mixins and nested rules readable.SCSS FormatterFormat SCSS/Sass stylesheets with Prettier, handling nesting, variables, mixins and maps.CSS BeautifierBeautify minified or messy CSS into readable, consistently indented rules with one declaration per line.