protected function createDomDocument($html): \DOMDocument
    {
        $document = new \DOMDocument('1.0');
        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $document->loadHTML($html);
        /** @var \LibXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        foreach ($errors as $error) {
            if (LIBXML_ERR_ERROR === $error->level || LIBXML_ERR_FATAL === $error->level) {
                throw new SourceException(
                    sprintf('%s at %d:%d', trim($error->message), $error->line, $error->column),
                    $error->code
                );
            }
        }

        return $document;
    }
protected function createDomDocument($html): \DOMDocument
    {
        $document = new \DOMDocument('1.0');
        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $document->loadHTML($html);
        /** @var \LibXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        foreach ($errors as $error) {
            if (LIBXML_ERR_ERROR === $error->level || LIBXML_ERR_FATAL === $error->level) {
                throw new SourceException(
                    sprintf('%s at %d:%d', trim($error->message), $error->line, $error->column),
                    $error->code
                );
            }
        }

        return $document;
    }
protected function createDomDocument ( $ html ) : \ DOMDocument { $ document = new \ DOMDocument ( '1.0' ) ; $ previousValue = libxml_use_internal_errors ( true ) ; libxml_clear_errors ( ) ; $ document -> loadHTML ( $ html ) ; /** @var \LibXMLError[] $errors */ $ errors = libxml_get_errors ( ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( $ previousValue ) ; foreach ( $ errors as $ error ) { if ( LIBXML_ERR_ERROR === $ error -> level || LIBXML_ERR_FATAL === $ error -> level ) { throw new SourceException ( sprintf ( '%s at %d:%d' , trim ( $ error -> message ) , $ error -> line , $ error -> column ) , $ error -> code ) ; } } return $ document ; }
Create DOMDocument from HTML string.

@param string $html

@return \DOMDocument

@throws SourceException On invalid HTML.

@since 1.7
Create DOMDocument from HTML string .