public function loadContent(string $content, $encoding='UTF-8')
    {
        $this->preserve_no_newlines = (strpos($content, '<') !== false && strpos($content, "\n") === false);

        if (!\is_bool($this->xml_mode)) {
            $this->xml_mode = (stripos($content, '<?xml') === 0);
        }

        $this->xml_print_pi = (stripos($content, '<?xml') === 0);

        $xml_pi_node_added = false;
        if (!$this->xml_mode && $encoding && stripos($content, '<?xml') === false) {
            $content = '<?xml encoding="'.$encoding.'">'.$content; // add pi node to make libxml use the correct encoding
            $xml_pi_node_added = true;
        }

        libxml_disable_entity_loader(true);
        libxml_use_internal_errors(true);

        $dom_document = new \DOMDocument('1.0', $encoding);
        $dom_document->strictErrorChecking = false;
        $dom_document->validateOnParse = false;
        $dom_document->recover = true;

        if ($this->xml_mode) {
            $dom_document->loadXML($content, $this->libxml_options);
        } else {
            $dom_document->loadHTML($content, $this->libxml_options);
        }

        $this->setDomDocument($dom_document);

        if ($xml_pi_node_added) { // pi node added, now remove it
            foreach ($dom_document->childNodes as $node) {
                if ($node->nodeType === XML_PI_NODE) {
                    $dom_document->removeChild($node);
                    break;
                }
            }
        }

        foreach ($dom_document->childNodes as $node) {
            $this->nodes[] = $node;
        }

        $this->length = \count($this->nodes);
    }
public function loadContent(string $content, $encoding='UTF-8')
    {
        $this->preserve_no_newlines = (strpos($content, '<') !== false && strpos($content, "\n") === false);

        if (!\is_bool($this->xml_mode)) {
            $this->xml_mode = (stripos($content, '<?xml') === 0);
        }

        $this->xml_print_pi = (stripos($content, '<?xml') === 0);

        $xml_pi_node_added = false;
        if (!$this->xml_mode && $encoding && stripos($content, '<?xml') === false) {
            $content = '<?xml encoding="'.$encoding.'">'.$content; // add pi node to make libxml use the correct encoding
            $xml_pi_node_added = true;
        }

        libxml_disable_entity_loader(true);
        libxml_use_internal_errors(true);

        $dom_document = new \DOMDocument('1.0', $encoding);
        $dom_document->strictErrorChecking = false;
        $dom_document->validateOnParse = false;
        $dom_document->recover = true;

        if ($this->xml_mode) {
            $dom_document->loadXML($content, $this->libxml_options);
        } else {
            $dom_document->loadHTML($content, $this->libxml_options);
        }

        $this->setDomDocument($dom_document);

        if ($xml_pi_node_added) { // pi node added, now remove it
            foreach ($dom_document->childNodes as $node) {
                if ($node->nodeType === XML_PI_NODE) {
                    $dom_document->removeChild($node);
                    break;
                }
            }
        }

        foreach ($dom_document->childNodes as $node) {
            $this->nodes[] = $node;
        }

        $this->length = \count($this->nodes);
    }
public function loadContent ( string $ content , $ encoding = 'UTF-8' ) { $ this -> preserve_no_newlines = ( strpos ( $ content , '<' ) !== false && strpos ( $ content , "\n" ) === false ) ; if ( ! \ is_bool ( $ this -> xml_mode ) ) { $ this -> xml_mode = ( stripos ( $ content , '<?xml' ) === 0 ) ; } $ this -> xml_print_pi = ( stripos ( $ content , '<?xml' ) === 0 ) ; $ xml_pi_node_added = false ; if ( ! $ this -> xml_mode && $ encoding && stripos ( $ content , '<?xml' ) === false ) { $ content = '<?xml encoding="' . $ encoding . '">' . $ content ; // add pi node to make libxml use the correct encoding $ xml_pi_node_added = true ; } libxml_disable_entity_loader ( true ) ; libxml_use_internal_errors ( true ) ; $ dom_document = new \ DOMDocument ( '1.0' , $ encoding ) ; $ dom_document -> strictErrorChecking = false ; $ dom_document -> validateOnParse = false ; $ dom_document -> recover = true ; if ( $ this -> xml_mode ) { $ dom_document -> loadXML ( $ content , $ this -> libxml_options ) ; } else { $ dom_document -> loadHTML ( $ content , $ this -> libxml_options ) ; } $ this -> setDomDocument ( $ dom_document ) ; if ( $ xml_pi_node_added ) { // pi node added, now remove it foreach ( $ dom_document -> childNodes as $ node ) { if ( $ node -> nodeType === XML_PI_NODE ) { $ dom_document -> removeChild ( $ node ) ; break ; } } } foreach ( $ dom_document -> childNodes as $ node ) { $ this -> nodes [ ] = $ node ; } $ this -> length = \ count ( $ this -> nodes ) ; }
Load html or xml content

@param string $content
@param string $encoding

@return void
Load html or xml content