有谁知道Linux兼容的命令行html格式化程序?你知道,我可以传递一个看起来像这样的文件:
<html>
<body>
<p>
hi
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它给了我:
<html>
<body>
<p>
hi
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我正在使用PHP来生成这个html,所以如果有一些方便的方法来通过PHP我这样做,我想念?
你可能正在寻找Tidy.它清理和格式化XML和HTML.还有一个PHP扩展,但您可能需要缓冲输出并将其传递到那里.
编辑:
一个代码示例:
ob_start();
// output your html
$output = ob_get_flush();
// Specify configuration
$config = array(
'indent' => true,
'output-xhtml' => true,
'wrap' => 200);
// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
// Output
echo $tidy;
Run Code Online (Sandbox Code Playgroud)
我没有测试这个,但它应该工作.