public static function htmlToDomDocument($html)
    {
        if (!$html) {
            $html = '';
        }

        // Transform multibyte entities which otherwise display incorrectly.
        $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');

        // Internal errors enabled as HTML5 not fully supported.
        libxml_use_internal_errors(true);

        // Instantiate new DOMDocument object, and then load in UTF-8 HTML.
        $dom = new DOMDocument();
        $dom->encoding = 'UTF-8';
        $dom->loadHTML("<div>$html</div>");

        return $dom;
    }
public static function htmlToDomDocument($html)
    {
        if (!$html) {
            $html = '';
        }

        // Transform multibyte entities which otherwise display incorrectly.
        $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');

        // Internal errors enabled as HTML5 not fully supported.
        libxml_use_internal_errors(true);

        // Instantiate new DOMDocument object, and then load in UTF-8 HTML.
        $dom = new DOMDocument();
        $dom->encoding = 'UTF-8';
        $dom->loadHTML("<div>$html</div>");

        return $dom;
    }
public static function htmlToDomDocument ( $ html ) { if ( ! $ html ) { $ html = '' ; } // Transform multibyte entities which otherwise display incorrectly. $ html = mb_convert_encoding ( $ html , 'HTML-ENTITIES' , 'UTF-8' ) ; // Internal errors enabled as HTML5 not fully supported. libxml_use_internal_errors ( true ) ; // Instantiate new DOMDocument object, and then load in UTF-8 HTML. $ dom = new DOMDocument ( ) ; $ dom -> encoding = 'UTF-8' ; $ dom -> loadHTML ( "<div>$html</div>" ) ; return $ dom ; }
Builds a DOMDocument object from a string containing HTML.
@param string $html HTML to load
@returns DOMDocument Returns a DOMDocument object.
Builds a DOMDocument object from a string containing HTML .