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

Breadcrumb

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

function Crawler::innerText

Returns only the inner text that is the direct descendent of the current node, excluding any child nodes.

Parameters

bool $normalizeWhitespace Whether whitespaces should be trimmed and normalized to single spaces:

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function innerText(bool $normalizeWhitespace = true) : string {
    foreach ($this->getNode(0)->childNodes as $childNode) {
        if (\XML_TEXT_NODE !== $childNode->nodeType && \XML_CDATA_SECTION_NODE !== $childNode->nodeType) {
            continue;
        }
        if (!$normalizeWhitespace) {
            return $childNode->nodeValue;
        }
        if ('' !== trim($childNode->nodeValue)) {
            return $this->normalizeWhitespace($childNode->nodeValue);
        }
    }
    return '';
}
RSS feed
Powered by Drupal