Does anyone know of a linux-compatible command line html formatter? You know, something where I could pass it a file that looks like:
<html>
<body>
<p>
hi
</p>
</body>
</html>
And it gives me:
<html>
<body>
<p>
hi
</p>
</body>
</html>
I'm using PHP to generate this html, so if there is some handy way to do this via php that I'm missing?
You are probably looking for Tidy. It cleans and formats XML and HTML. There is also a PHP extension, but you would probably need to buffer your output and pass it through there.
Edit:
A code example:
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;
I didn't test this, but it should work.
Take a look at PHP's Tidy offering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With