PHP | XMLWriter setIndent()函数
XMLWriter::setIndent()函数是PHP中的一个内置函数,用于在默认情况下关闭的 XML 文档中打开/关闭缩进。
句法:
bool XMLWriter::setIndent( bool $indent )
参数:此函数接受单个参数$indent ,它包含一个布尔值,表示 TRUE 用于启用缩进或 FALSE 用于禁用缩进。
返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。
下面的示例说明了PHP中的XMLWriter::setIndent()函数:
示例 1:
openURI('php://output');
// Start the document
$writer->startDocument('1.0', 'UTF-8');
// Enable the indents
$writer->setIndent(true);
// Start a element
$writer->startElement('div');
// Start a element
$writer->startElement('h1');
// Add value to the element
$writer->text('Indented Text');
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:
Indented Text
示例 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('p');
// Start a element
$writer->startElement('h1');
// Add value to the element
$writer->text('GeeksforGeeks');
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the element
$writer->endElement();
// End the document
$writer->endDocument();
?>
输出:
******
************
GeeksforGeeks
******
参考: https://www. PHP.net/manual/en/函数.xmlwriter-set-indent。 PHP