php8.5
Home/ Manual/ dom / tokenlist/ Dom\TokenList::contains

Dom\TokenList::contains

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Returns whether the list contains a given token

Description

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

Dom\TokenList::contains example

Checks whether two classes are present on the paragraph.

php
<?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:

output
bool(true)
bool(false)

Source: reference/dom/dom/tokenlist/contains.xml · from the official PHP manual (php/doc-en)