PHP Serialize / Unserialize
Converts PHP serialized strings to readable JSON and back, safely.
Fix the indentation of PHP code. Blocks, arrays, and switch statements are re-indented, while strings, heredocs, comments, and inline HTML are left alone.
.php file.The formatter is deliberately conservative. It reads the code as PHP tokens and changes only the whitespace at the start and end of each line.
{, (, or [ left open at the end of a line indents the following lines by one level, and the matching closer brings them back.switch, the body of each case and default is indented one level below it./* ... */ comments are copied unchanged, because their whitespace is part of the content.<?php ... ?> is HTML and is kept as written.Input:
<?php
function total(array $items): float {
$sum = 0;
foreach ($items as $item) {
switch ($item['type']) {
case 'book':
$sum += $item['price'] * 0.9;
break;
default:
$sum += $item['price'];
}
}
return $sum;
}Formatted with 4 spaces:
<?php
function total(array $items): float {
$sum = 0;
foreach ($items as $item) {
switch ($item['type']) {
case 'book':
$sum += $item['price'] * 0.9;
break;
default:
$sum += $item['price'];
}
}
return $sum;
}
if ($a) foo(); split over two lines, are not indented.It uses PSR-12's 4-space indentation and case indentation, but it doesn't rewrite braces, spacing, or line length. Use PHP-CS-Fixer for full PSR-12 formatting.
No. Lines inside strings, heredoc, nowdoc, and block comments are kept exactly as they are, because changing their indentation would change your data.
Yes. HTML outside PHP tags is left alone, and the PHP inside the tags is indented. Blade directives such as @if are treated as HTML.
No. It is formatted in your browser.
Often used together with the PHP Formatter.
Converts PHP serialized strings to readable JSON and back, safely.
Runs printf and sprintf format strings with test arguments and explains each placeholder.
Beautifies HTML with consistent indentation, including inline CSS and JavaScript.