Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipluate HTML documents, but also traverse the document tree.
Tidy is currently available for PHP 4.3.x and PHP 5 as a PECL extension. To use Tidy, you will need libtidy installed,available on the tidy homepage http://tidy.sourceforge.net/.
The tidy extension is available from PECL http://pecl.php.net/package/tidy