Zend Developer Zone | Tidying up your HTML with PHP 5
http://devzone.zend.com/node/view/id/761
"The Tidy extension is new in PHP 5, and is available from PHP version 5.0b3 upward. It is based on the TidyLib library, and allows the developer to validate, repair, and parse HTML, XHTML and XML documents from within PHP."