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
There is an extension for PHPUnit that does html validation here: https://github.com/xvoland/html-validate