XMLWriter::startComment()函數是PHP中的內置函數,用於啟動注釋。稍後需要使用XMLWriter::endComment()函數關閉此注釋。
用法:
bool XMLWriter::startComment( void )
參數:此函數不接受任何參數。
返回值:如果成功,此函數將返回TRUE,否則將返回FALSE。
以下示例說明了PHP中的XMLWriter::startComment()函數:
範例1:
<?php
// Create a new XMLWriter instance
$writer = new XMLWriter();
// Create the output stream as PHP
$writer->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();
?>
輸出:
<?xml version="1.0" encoding="UTF-8"?> <div><!--This is a comment--></div>
程序2:
<?php
// Create a new XMLWriter instance
$writer = new XMLWriter();
// Create the output stream as PHP
$writer->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();
?>
輸出:
<?xml version="1.0" encoding="UTF-8"?> <div><!--This will not be visible.--> This is the visible text.</div>
參考: https://www.php.net/manual/en/function.xmlwriter-start-comment.php
相關用法
- PHP XMLWriter endAttribute()用法及代碼示例
- PHP XMLWriter startDtdAttlist()用法及代碼示例
- PHP XMLWriter endDtdEntity()用法及代碼示例
- PHP XMLWriter startAttributeNs()用法及代碼示例
- PHP XMLWriter endDocument()用法及代碼示例
- PHP XMLWriter endCdata()用法及代碼示例
- PHP XMLWriter startAttribute()用法及代碼示例
- PHP XMLWriter startCdata()用法及代碼示例
- PHP XMLWriter startDocument()用法及代碼示例
- PHP XMLWriter setIndent()用法及代碼示例
- PHP XMLWriter endComment()用法及代碼示例
- PHP XMLWriter openUri()用法及代碼示例
- PHP XMLWriter endDtdAttlist()用法及代碼示例
- PHP XMLWriter endDtdElement()用法及代碼示例
- PHP XMLWriter endPi()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | XMLWriter startComment() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。