PHP 格式化工具
在浏览器中直接重新格式化 PHP 源代码。默认采用 PSR-12 友好设置,可切换大括号风格并规范化开始标签。
使用方法
- 1 粘贴你的 PHP 源代码。
- 2 选择大括号风格和缩进大小。
- 3 开启或关闭「规范化短开始标签」选项。
- 4 复制或下载处理后的结果。
为什么使用此工具
- 目前没有能在客户端运行的 PHP 语法解析器——这是一款基于规则的重新格式化工具,能够可靠地处理大括号和缩进。
- 默认设置贴近 PSR-12:K&R 风格大括号,4 个空格缩进。
- 完全在客户端处理——你的代码不会离开浏览器。
- 如需精确规范的格式化,请在本地运行 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">vendor/bin/pint</code> 或 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">php-cs-fixer</code>。
常见问题
这个工具符合 PSR-12 规范吗?
输出结果接近 PSR-12 标准(K&R 风格大括号、4 个空格缩进),但并未应用所有规则——换行规则、import 排序以及方法间距等未被处理。如需完全符合 PSR-12,请使用 Pint 或 PHP-CS-Fixer。
这个工具会影响模板中的 HTML 部分吗?
工具只会重新缩进包含 PHP 代码的行。对于 HTML/PHP 混合文件,HTML 片段中的缩进可能会丢失——处理模板请使用能识别 Blade 语法的格式化工具。
在找 HTML 格式化工具?
我们也有——参见 <a href="/html-formatter" class="underline">HTML 格式化工具</a>。
什么是 PHP 格式化工具?
PHP Formatter 是一款在浏览器中直接重新格式化 PHP 源代码的工具,默认设置贴近 PSR-12 规范。工具支持切换大括号风格、规范化开始标签,并对代码重新缩进,让代码结构更统一、更易读。由于处理过程完全在客户端完成,你的源代码不会离开本地设备。
功能特性
Brace-depth reindent
Re-indents blocks by brace nesting and normalizes brace placement to K&R or Allman.
PSR-12-friendly defaults
Sensible 4-space indentation and short-tag normalization out of the box.
100% private
Runs client-side — your PHP is never uploaded.
示例
Input
<?php
if ($x)
{
echo 1;
}
Output
<?php
if ($x) {
echo 1;
}
常见使用场景
-
1
Tidy pasted PHP
Fix indentation on a snippet copied from a log, email, or chat.
-
2
Normalize brace style
Convert between K&R and Allman brace placement across a block.
-
3
Quick readability pass
Improve layout before review without installing PHP-CS-Fixer locally.
Zerethon's PHP formatter reindents PHP source in your browser using PSR-12-friendly defaults, with a brace-style toggle (K&R or Allman) and short-tag normalization (`<?` → `<?php`). It is a lightweight brace-depth reindenter, not a full PHP-CS-Fixer — it tidies layout without reflowing long lines. Nothing is uploaded.
- 分类
- 开发者
- 价格
- 免费
- 隐私
- 基于浏览器
- 注册
- 无需
References
- PSR-12 — Extended Coding Style — PHP-FIG
- PHP Manual — php.net
隐私
除非另有说明,否则你的数据永远不会离开浏览器。PHP 格式化工具 完全在客户端运行 — 无需上传服务器,不记录日志,不追踪你输入的内容。
相关工具
在 Zerethon Social 上创作、分享与成长
免费注册。赚取积分,收集成就,与全球创作者建立联系。