PHP | XMLWriter startCdata()函数
XMLWriter::startCdata()函数是PHP中的一个内置函数,用于启动 CDATA。然后需要使用XMLWriter::endCdata()函数关闭此元素。 CDATA 是一个不被解析器解析但被识别为标记的文本块。
句法:
bool XMLWriter::startCdata( void )
参数:此函数不接受任何参数。
返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。
下面的示例说明了PHP中的XMLWriter::startCdata()函数:
示例 1:
openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Start a element
$writer->startElement('h1');
// Start the Cdata
$writer->startCdata();
// Add value to the Cdata
$writer->text('value');
// End the Cdata
$writer->endCdata();
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:
示例 2:
openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Start a element
$writer->startElement('p');
// Start the Cdata
$writer->startCdata();
// Add value to the Cdata which is not
// going to be visible on the webpage
$writer->text('This will be secret text,
not visible in browser');
// End the Cdata
$writer->endCdata();
// Add value to the element
$writer->text('GeeksforGeeks, portal for
Computer Science.');
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:
GeeksforGeeks, portal for Computer Science.
参考: https://www. PHP.net/manual/en/函数.xmlwriter-start-cdata。 PHP