The DOMComment class
(PHP 5, PHP 7, PHP 8)
简介
Represents comment nodes, characters delimited by <!--
and -->
.
类摘要
class DOMComment
extends
DOMCharacterData
{
/* 继承的属性 */
/* 方法 */
/* 继承的方法 */
public DOMNode::C14N(
bool
bool
?array
?array
): string|false
bool
$exclusive
= false
,bool
$withComments
= false
,?array
$xpath
= null
,?array
$nsPrefixes
= null
): string|false
public DOMNode::C14NFile(
string
bool
bool
?array
?array
): int|false
}string
$uri
,bool
$exclusive
= false
,bool
$withComments
= false
,?array
$xpath
= null
,?array
$nsPrefixes
= null
): int|false
目录
- DOMComment::__construct — Creates a new DOMComment object

User Contributed Notes 1 note
npelov at croler dot net ¶
9 months ago
Note that textContent property of a comment is not entity decoded, it is decoded in DOMElement::textContent :
<?php
$xml = new DOMDocument();
$xml->loadXML('<?xml version="1.0" encoding="utf-8"?>
<configuration version="2">
<!-- test --> -->
test -->
</configuration>'
);
$xpath = new DOMXPath($xml);
$comments = $xpath->query('//comment()');
$elements = $xpath->query('//configuration');
echo $comments[0]->textContent;
// result: test -->
echo $elements[0]->textContent;
// result: test -->
?>