W3cubDocs

/PHP

The Dom\TokenList class

Introduction

(PHP 8 >= 8.4.0)

Represents a set of tokens in an attribute (e.g. class names).

Class synopsis

final class Dom\TokenList implements IteratorAggregate, Countable {
/* Properties */
public readonly int $length;
public string $value;
/* Methods */
public add(string ...$tokens): void
public contains(string $token): bool
public count(): int
public getIterator(): Iterator
public item(int $index): ?string
public remove(string ...$tokens): void
public replace(string $token, string $newToken): bool
public supports(string $token): bool
public toggle(string $token, ?bool $force = null): bool
}

Properties

length
The number of tokens.
value
The value of the attribute linked to this object.

Notes

Note: The DOM extension uses UTF-8 encoding when working with methods or properties. The parser methods auto-detect the encoding or allow the caller to specify an encoding.

Note: Tokens in the list can be accessed by array syntax.

Table of Contents

© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/class.dom-tokenlist.php