Use DOMDocument for typeahead to fix broken end tags