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

Breadcrumb

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

function Crawler::text

Returns the text of the first node of the list.

Pass true as the second argument to normalize whitespaces.

Parameters

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

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

Throws

\InvalidArgumentException When current node is empty

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function text(?string $default = null, bool $normalizeWhitespace = true) : string {
    if (!$this->nodes) {
        if (null !== $default) {
            return $default;
        }
        throw new \InvalidArgumentException('The current node list is empty.');
    }
    $text = $this->getNode(0)->nodeValue;
    if ($normalizeWhitespace) {
        return $this->normalizeWhitespace($text);
    }
    return $text;
}
RSS feed
Powered by Drupal