I LOVE PHP 8.4's new DOM processing stuff. I recently had to write some DOM processing code in PHP and was really hoping to make use of it, but it turns out my code had to be compatible with PHP 8.2 (for complicated reasons) and I couldn't make the most of the new functionality. Boo!

I pretty-print all the HTML output by DanQ.me, but my approach is different (and works with older versions of PHP, as a fringe bonus). I put an ob_start in my header, with a callback function that (among other things) prettifies everything that's been written. It does this using an instance of tidy for PHP, with 'indent' => true and 'output-html' => true parameters to its `parseString()` before calling `cleanRepair()`. I've been doing this for a few years and it seems to work pretty well. It seems my approach is probably more-performant than doing it all in PHP, but so long as you're caching it probably doesn't make a significant difference.