This may be a dumb question, but do you make unit tests for the HTML output of your PHP functions/scripts?
I try to keep my HTML and my PHP separate - i.e. HTML includes
A lot of these links are either dead or old. Take a look at http://phpfui.com/PHPFUI/HTMLUnitTester It validated HTML and CSS against w3.org standards. I wrote it because I could not find any recent and currently supported PHP library to do it. Other solutions were based on an old version of PHPUnit or not compatible with modern PHP code.
It uses the W3C HTML validator service which I would recommend running locally. It is all explained in the readme file in configuration. The beauty of the library is that it does not do the actual validation, but calls the W3C.org code, so it will always be up to date if you keep your local install current.
Hope this helps.