📜  PHP | XMLWriter startComment()函数

📅  最后修改于: 2022-05-13 01:56:47.494000             🧑  作者: Mango

PHP | XMLWriter startComment()函数

XMLWriter::startComment()函数是PHP中的一个内置函数,用于开始注释。稍后需要使用XMLWriter::endComment()函数关闭此评论。

句法:

bool XMLWriter::startComment( void )

参数:此函数不接受任何参数。

返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。

下面的示例说明了PHP中的XMLWriter::startComment()函数

示例 1:

openURI('php://output');
  
// Start the document
$writer->startDocument('1.0', 'UTF-8');
  
// Start a element
$writer->startElement('div');
  
// Start a comment
$writer->startComment();
  
// Add text to the comment
$writer->text('This is a comment');
  
// End the comment
$writer->endComment();
  
// End the element
$writer->endElement();
  
// End the document
$writer->endDocument();
?>

输出:


方案二:

openURI('php://output');
  
// Start the document
$writer->startDocument('1.0', 'UTF-8');
  
// Start a element
$writer->startElement('div');
  
// Start a comment
$writer->startComment();
  
// Add text to the comment which will not be visible
$writer->text('This will not be visible.');
  
// End the comment
$writer->endComment();
  
// Add value to the element
$writer->text('This is the visible text.');
  
// End the element
$writer->endElement();
  
// End the document
$writer->endDocument();
?>

输出:


This is the visible text.

参考: https://www. PHP.net/manual/en/函数.xmlwriter-start-comment。 PHP