NOTE: $enable can be integer as in example, or boolean.
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL xmlwriter >= 0.1.0)
XMLWriter::setIndent -- xmlwriter_set_indent — Toggle indentation on/off
Stile orientato agli oggetti
Stile procedurale
Toggles indentation on or off.
xmlwriter
Solo per chiamate procedurali. La resource XMLWriter che è stata modificata. Questa risorsa deriva da una chiamata a xmlwriter_open_uri() or xmlwriter_open_memory().
enable
Whether indentation is enabled.
Restituisce true
in caso di successo, false
in caso di fallimento.
Versione | Descrizione |
---|---|
8.0.0 |
writer expects an XMLWriter
instance now; previously, a resource was expected.
|
Example #1 XMLWriter::setIndent() and mixed Content
Enabling indentation is not suitable for mixed content, because the indent string is also inserted before inline elements.
<?php
$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(2);
$writer->startDocument();
$writer->startElement('p');
$writer->text('before');
$writer->writeElement('a', 'element');
$writer->text('after');
$writer->endElement();
$writer->endDocument();
echo $writer->outputMemory();
?>
Il precedente esempio visualizzerà:
<?xml version="1.0"?> <p>before <a>element</a> after</p>
Nota:
The indent is reset when an xmlwriter is opened.