array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'domcdatasection.construct.php', 1 => 'DOMCdataSection::__construct', ), 'up' => array ( 0 => 'class.domcdatasection.php', 1 => 'DOMCdataSection', ), 'prev' => array ( 0 => 'class.domcdatasection.php', 1 => 'DOMCdataSection', ), 'next' => array ( 0 => 'class.domcharacterdata.php', 1 => 'DOMCharacterData', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/dom/domcdatasection/construct.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
DOMCdataSection::__construct — Constructs a new DOMCdataSection object
Constructs a new CDATA node. This works like the DOMText class.
data
The value of the CDATA node. If not supplied, an empty CDATA node is created.
示例 #1 Creating a new DOMCdataSection object
<?php
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->appendChild(new DOMElement('root'));
$text = $element->appendChild(new DOMCdataSection('root value'));
echo $dom->saveXML();
?>
以上示例会输出:
<?xml version="1.0" encoding="utf-8"?> <root><![CDATA[root value]]></root>