(PHP 5, PHP 7, PHP 8)
tidyNode::isComment — 检查节点是否表示注释
此函数没有参数。
示例 #1 从混合 HTML 文档中提取注释
<?php
$html = <<< HTML
<html><head>
<?php echo '<title>title</title>'; ?>
<# 
 /* JSTE code */
 alert('Hello World'); 
#>
</head>
<body>
<?php
 // PHP code
 echo 'hello world!';
?>
<%
 /* ASP code */
 response.write("Hello World!")
%>
<!-- Comments -->
Hello World
</body></html>
Outside HTML
HTML;
$tidy = tidy_parse_string($html);
$num = 0;
get_nodes($tidy->html());
function get_nodes($node) {
 // 检查当前节点是否为请求类型
 if($node->isComment()) {
 echo "\n\n# comment node #" . ++$GLOBALS['num'] . "\n";
 echo $node->value;
 }
 // 检查当前节点是否有子节点
 if($node->hasChildren()) {
 foreach($node->child as $child) {
 get_nodes($child);
 }
 }
}
?>以上示例将输出
# comment node #1 <!-- Comments -->
