PHP 8.4.2 Released!

Dom\TokenList::contains

(PHP 8 >= 8.4.0)

Dom\TokenList::containsReturns whether the list contains a given token

说明

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

Returns whether the list contains token.

参数

token
The token.

返回值

Returns true if the list contains token, false otherwise.

示例

示例 #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'),
);
?>

以上示例会输出:

bool(true)
bool(false)
添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top