Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::addHtmlContent

Adds an HTML content to the list of nodes.

The libxml errors are disabled when the content is parsed.

If you want to get parsing errors, be sure to enable internal errors via libxml_use_internal_errors(true) and then, get the errors via libxml_get_errors(). Be sure to clear errors with libxml_clear_errors() afterward.

1 call to Crawler::addHtmlContent()
Crawler::addContent in vendor/symfony/dom-crawler/Crawler.php
Adds HTML/XML content.

File

vendor/symfony/dom-crawler/Crawler.php, line 172

Class

Crawler
Crawler eases navigation of a list of \DOMNode objects.

Namespace

Symfony\Component\DomCrawler

Code

public function addHtmlContent(string $content, string $charset = 'UTF-8') : void {
    $dom = $this->parseHtmlString($content, $charset);
    $this->addDocument($dom);
    $base = $this->filterRelativeXPath('descendant-or-self::base')
        ->extract([
        'href',
    ]);
    $baseHref = current($base);
    if (\count($base) && $baseHref) {
        if ($this->baseHref) {
            $linkNode = $dom->createElement('a');
            $linkNode->setAttribute('href', $baseHref);
            $link = new Link($linkNode, $this->baseHref);
            $this->baseHref = $link->getUri();
        }
        else {
            $this->baseHref = $baseHref;
        }
    }
}
RSS feed
Powered by Drupal