gpt4 book ai didi

php - 适用于 Linux 的命令行 html 格式化程序(或在 PHP 中执行此操作的方法)?

转载 作者:太空狗 更新时间:2023-10-29 15:43:19 24 4
gpt4 key购买 nike

有人知道兼容 linux 的命令行 html 格式化程序吗?你知道,我可以向它传递一个看起来像这样的文件:

<html>
<body>
<p>
hi
</p>
</body>
</html>

它给了我:

<html>
<body>
<p>
hi
</p>
</body>
</html>

我正在使用 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;

我没有测试这个,但它应该可以工作。

关于php - 适用于 Linux 的命令行 html 格式化程序(或在 PHP 中执行此操作的方法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1369713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com