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

Breadcrumb

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

function Crawler::html

Returns the first node of the list as HTML.

Parameters

string|null $default When not null: the value to return when the current node is empty:

Throws

\InvalidArgumentException When current node is empty

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function html(?string $default = null) : string {
    if (!$this->nodes) {
        if (null !== $default) {
            return $default;
        }
        throw new \InvalidArgumentException('The current node list is empty.');
    }
    $node = $this->getNode(0);
    $owner = $node->ownerDocument;
    if ($this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
        $owner = $this->html5Parser;
    }
    $html = '';
    foreach ($node->childNodes as $child) {
        $html .= $owner->saveHTML($child);
    }
    return $html;
}
RSS feed
Powered by Drupal