src/Request.php
public function getHtmlContent()
    {
        if ($this->htmlContent === null) {
            try {
                if (($content = $this->getContent()) === '') {
                    return $this->htmlContent = false;
                }

                $errors = libxml_use_internal_errors(true);
                $this->htmlContent = new \DOMDocument();

                if ((mb_detect_encoding($content) === 'UTF-8') && mb_check_encoding($content, 'UTF-8')) {
                    $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
                    $content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content);
                }

                //Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)
                //$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'], '', $content);

                $this->htmlContent->loadHTML($content);
                libxml_use_internal_errors($errors);
            } catch (\Exception $E) {
                return $this->htmlContent = false;
            }
        }

        return $this->htmlContent;
    }
public function getHtmlContent()
    {
        if ($this->htmlContent === null) {
            try {
                if (($content = $this->getContent()) === '') {
                    return $this->htmlContent = false;
                }

                $errors = libxml_use_internal_errors(true);
                $this->htmlContent = new \DOMDocument();

                if ((mb_detect_encoding($content) === 'UTF-8') && mb_check_encoding($content, 'UTF-8')) {
                    $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
                    $content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content);
                }

                //Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)
                //$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'], '', $content);

                $this->htmlContent->loadHTML($content);
                libxml_use_internal_errors($errors);
            } catch (\Exception $E) {
                return $this->htmlContent = false;
            }
        }

        return $this->htmlContent;
    }
public function getHtmlContent ( ) { if ( $ this -> htmlContent === null ) { try { if ( ( $ content = $ this -> getContent ( ) ) === '' ) { return $ this -> htmlContent = false ; } $ errors = libxml_use_internal_errors ( true ) ; $ this -> htmlContent = new \ DOMDocument ( ) ; if ( ( mb_detect_encoding ( $ content ) === 'UTF-8' ) && mb_check_encoding ( $ content , 'UTF-8' ) ) { $ content = mb_convert_encoding ( $ content , 'HTML-ENTITIES' , 'UTF-8' ) ; $ content = preg_replace ( '/<head[^>]*>/' , '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">' , $ content ) ; } //Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny) //$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'], '', $content); $ this -> htmlContent -> loadHTML ( $ content ) ; libxml_use_internal_errors ( $ errors ) ; } catch ( \ Exception $ E ) { return $ this -> htmlContent = false ; } } return $ this -> htmlContent ; }
Get the content of the url as a DOMDocument object

@return \DOMDocument|false
Get the content of the url as a DOMDocument object