Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Dom\TokenList::addDom\TokenList::count>
^Dom\TokenListLast updated: Mon, 26 Oct 2026

Dom\TokenList::contains

(PHP 8 >= 8.4.0)

Dom\TokenList::contains — Returns whether the list contains a given token

Description

public function Dom\TokenList::contains(string $token): bool

Returns whether the list contains token.

Parameters

token

The token.

Return Values

Returns true if the list contains token, false otherwise.

Examples

Example #1 Dom\TokenList::contains() example

Checks whether two classes are present on the paragraph.

<?php
$dom = Dom\HTMLDocument::createFromString('<p class="font-bold important"></p>', LIBXML_NOERROR);
$p = $dom->body->firstChild;

$classList = $p->classList;
var_dump(
    $classList->contains('important'),
    $classList->contains('font-small'),
);
?>

The above example will output:

bool(true)
bool(false)

<Dom\TokenList::addDom\TokenList::count>
^Dom\TokenListLast updated: Mon, 26 Oct 2026