DOMComment::__construct()函数是PHP中的内置函数,可创建新的DOMComment对象。该对象是只读的,可以附加到文档中
用法:
public DOMComment::__construct( string $value)
参数:该函数接受一个包含注释的单个参数$value。
下面给出的程序说明了PHP中的DOMComment::__construct()函数:
计划1(简单评论):
<?php 
  
// Create a new DOM Document 
$dom = new DOMDocument('1.0', 'iso-8859-1'); 
  
// Create a h1 element 
$element = $dom->appendChild(new DOMElement('h1')); 
  
// Create a DOMComment 
$comment = $element->appendChild( 
        new DOMComment('This line is a comment')); 
  
echo $dom->saveXML(); 
?>输出:
<?xml version="1.0" encoding="iso-8859-1"?> <h1><!--This line is a comment--></h1>

计划2(在元素中使用注释):
<?php 
  
// Create a new DOM Document 
$dom = new DOMDocument('1.0', 'iso-8859-1'); 
  
// Create a h1 element 
$element = $dom->appendChild(new DOMElement('h1')); 
  
// Create a DOMCdataSection  
$comment = $element->appendChild(new DOMComment( 
        'This line is a comment about content')); 
  
// Create a div element 
$element = $element->appendChild(new DOMElement( 
          'div', 'This is the actual content')); 
  
echo $dom->saveXML(); 
?>输出:
<?xml version="1.0" encoding="iso-8859-1"?> <h1><!--This line is a comment about content--> <div>This is the actual content</div></h1>

参考: https://www.php.net/manual/en/domcomment.construct.php
相关用法
- d3.js d3.hcl()用法及代码示例
- p5.js arc()用法及代码示例
- PHP abs()用法及代码示例
- PHP each()用法及代码示例
- d3.js d3.rgb()用法及代码示例
- d3.js d3.lab()用法及代码示例
- PHP end()用法及代码示例
- PHP cos( )用法及代码示例
- PHP Ds\Map put()用法及代码示例
- PHP sin( )用法及代码示例
- d3.js d3.mean()用法及代码示例
注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | DOMComment __construct() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
