PHP | XMLWriter setIndentString()函数
XMLWriter::setIndentString()函数是PHP中的一个内置函数,用于设置字符串,该字符串将用于缩进生成的 xml 的每个元素/属性。
句法:
bool XMLWriter::setIndentString( string $indentString )
参数:此函数接受单个参数$indentString ,其中包含要用作缩进的字符串。
返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。
下面的例子说明了PHP中的XMLWriter::setIndentString()函数:
示例 1:
openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Enable the indents
$writer->setIndent(true);
// Set the indent string
$writer->setIndentString('--->');
// Start a element
$writer->startElement('div');
// Start a element
$writer->startElement('div');
// Add value to the element
$writer->text('Hello World');
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:按 Ctrl+U 查看 XML
示例 2:
openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Enable the indents
$writer->setIndent(true);
// Set the indent string
$writer->setIndentString('--->');
// Start a element
$writer->startElement('div');
// Start a element
$writer->startElement('div');
// Start a element
$writer->startElement('div');
// Add value to the element
$writer->text('This is a multi-indented text.');
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:
参考: https://www. PHP.net/manual/en/函数.xmlwriter-set-indent-string。 PHP