as invalid tag * * @param $html * * @return DOMDocument */ public static function createDOMDocumentFromText( $html ) { $error_setting = libxml_use_internal_errors( true ); $document = new \DOMDocument(); if ( !empty( $html ) ) { //encode for correct load $document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ); } // clear user generated html parsing errors libxml_clear_errors(); libxml_use_internal_errors( $error_setting ); return $document; } }