array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'dom-tokenlist.contains.php', 1 => 'Dom\\TokenList::contains', 2 => 'Returns whether the list contains a given token', ), 'up' => array ( 0 => 'class.dom-tokenlist.php', 1 => 'Dom\\TokenList', ), 'prev' => array ( 0 => 'dom-tokenlist.add.php', 1 => 'Dom\\TokenList::add', ), 'next' => array ( 0 => 'dom-tokenlist.count.php', 1 => 'Dom\\TokenList::count', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/dom/dom/tokenlist/contains.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 8 >= 8.4.0)
Dom\TokenList::contains — Returns whether the list contains a given token
token示例 #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)