PHP | XMLWriter startComment() Function
Last Updated :
07 Mar, 2024
The XMLWriter::startComment() function is an inbuilt function in PHP which is used to start comment. This comment later needs to be closed using XMLWriter::endComment() function.
Syntax:
bool XMLWriter::startComment( void )
Parameters:This function doesn’t accept any parameter.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLWriter::startComment() function in PHP:
Example 1:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'div' );
$writer ->startComment();
$writer ->text( 'This is a comment' );
$writer ->endComment();
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
<?xml version="1.0" encoding="UTF-8"?>
<div><!--This is a comment--></div>
Program 2:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'div' );
$writer ->startComment();
$writer ->text( 'This will not be visible.' );
$writer ->endComment();
$writer ->text( 'This is the visible text.' );
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
<?xml version="1.0" encoding="UTF-8"?>
<div><!--This will not be visible.-->
This is the visible text.</div>
Share your thoughts in the comments
Please Login to comment...