XMLWriter::startCdata()函数是PHP中的内置函数,用于启动CDATA。然后需要使用XMLWriter::endCdata()函数关闭此元素。 CDATA是一个文本块,无法被解析器解析,但是被识别为标记。
用法:
bool XMLWriter::startCdata( void )
参数:此函数不接受任何参数。
返回值:如果成功,此函数将返回TRUE,否则将返回FALSE。
以下示例说明了PHP中的XMLWriter::startCdata()函数:
范例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('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();
?>
输出:
<?xml version="1.0" encoding="UTF-8"?> <h1><![CDATA[value]]></h1>
范例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('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();
?>
输出:
<?xml version="1.0" encoding="UTF-8"?> <p><![CDATA[This will be secret text, not visible in browser]]> GeeksforGeeks, portal for Computer Science. </p>
参考: https://www.php.net/manual/en/function.xmlwriter-start-cdata.php
相关用法
- PHP XMLWriter startComment()用法及代码示例
- PHP XMLWriter startDocument()用法及代码示例
- PHP XMLWriter endElement()用法及代码示例
- PHP XMLWriter openUri()用法及代码示例
- PHP XMLWriter setIndent()用法及代码示例
- PHP XMLWriter fullEndElement()用法及代码示例
- PHP XMLWriter startAttributeNs()用法及代码示例
- PHP XMLWriter endPi()用法及代码示例
- PHP XMLWriter startAttribute()用法及代码示例
- PHP XMLWriter endComment()用法及代码示例
- PHP XMLWriter endDtdEntity()用法及代码示例
- PHP XMLWriter startDtdAttlist()用法及代码示例
- PHP XMLWriter endDocument()用法及代码示例
- PHP XMLWriter endCdata()用法及代码示例
- PHP XMLWriter endAttribute()用法及代码示例
注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | XMLWriter startCdata() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。